测量应用程序启动性能
我在 Windows 上使用 C++/CLI。这是一个使用 /clr 构建的 MFC 应用程序。
我想测试我的应用程序启动需要多长时间。第一次用了10秒,后来就用了4秒、4秒、5秒。我假设这是由于 Windows 缓存 DLL 造成的。
是否有某种工具可以让我从缓存中删除目录,以便我的测试条件每次都相同?我不想在测试之间重新启动:)
I'm using C++/CLI on Windows. It's an MFC app built with /clr.
I want to test how long it takes my application to start up. The first time it took 10s, but subsequently it took 4s, 4s, 5s. I'm assuming this is due to Windows caching the DLLs.
Is there some tool that will allow me to remove a directory from the cache, so that my test conditions are the same each time? I don't want to have to reboot between tests :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用 .Net 框架,则很可能有 6 秒的时间等待框架初始化(加载 mscoree.dll 等)。 CLR 全面深入:提高应用程序启动性能 是一篇撰写的文章供 MSDN 杂志使用。
冷启动需要加载所有.Net Framework 并运行JIT 编译器来生成代码。
当您第二次启动该应用程序时,几乎所有操作都已完成。即 DLL 已加载,它可能会提取先前编译的代码等。
要减少启动时间,您可以做的最好的事情是在第一个窗口显示之前减少 .Net 框架调用的数量(因为所有这些都会需要先编译才能运行)并减少启动程序所需的磁盘 I/O 量。
一旦您的程序启动并运行,来自 .Net 的任何未编译的 IL 将在首次调用时由 JIT 编译器进行编译。
另外,据我所知,一旦加载了框架,就没有一种简单的方法可以在不重新启动的情况下卸载它(如果您可以卸载它的话)。在加载框架之前让虚拟机处于保存状态可以大大减少“重新启动”所需的时间。
If you're using the .Net framework, chances are those 6 seconds are waiting for the framework to initialize (load mscoree.dll, etc.). CLR Inside Out: Improving Application Startup Performance is an article that was written for the MSDN magazine.
A cold startup needs to load all of the .Net Framework as well as run the JIT compiler to generate the code.
When you launch the application a second time, almost all of that is done. i.e. The DLLs were loaded, it may pull the code that was previously compiled, etc.
The best thing you can do to decrease your startup time is to reduce the amount of .Net framework calls before your first window shows (since all of that will need to be compiled before it can run) and reduce the amount of disk I/O needed to launch your program.
Once your program is up and running, any uncompiled IL from .Net will be compiled by the JIT compiler when it is first called.
Also, as far as I know, once the Framework is loaded, there isn't an easy way to unload it without rebooting (if you can unload it at all). Having a virtual machine in a saved state just before loading the Framework could drastically reduce the time needed for "reboots".
Joshua所说的,加上,看看
What Joshua said, plus, look at the third paragraph of this answer.