测量应用程序启动性能

发布于 2024-08-06 11:04:55 字数 190 浏览 6 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青芜 2024-08-13 11:04:55

如果您使用 .Net 框架,则很可能有 6 秒的时间等待框架初始化(加载 mscoree.dll 等)。 CLR 全面深入:提高应用程序启动性能 是一篇撰写的文章供 MSDN 杂志使用。

冷启动需要加载所有.Net Framework 并运行JIT 编译器来生成代码。

在大多数情况下,冷启动受 I/O 限制。换句话说,等待数据所花费的时间比处理指令所花费的时间要多。启动应用程序所需的时间等于操作系统从磁盘获取代码所需的时间加上执行其他处理(例如 JITing IL 代码以及在启动路径中执行的任何其他初始化)所需的时间。应用。由于处理通常不是冷启动的瓶颈,因此任何应用程序启动性能调查的最初目标都是通过减少加载的代码量来减少磁盘访问。

当您第二次启动该应用程序时,几乎所有操作都已完成。即 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.

In most cases, cold startup is I/O bound. In other words, more time is spent waiting for data than is spent processing instructions. The time it takes to launch the application is equal to the time it takes the OS to fetch code from disk plus the time it takes to perform additional processing such as JITing the IL code and any other initialization that is performed in the startup path of the application. Since processing is usually not the bottleneck in a cold startup, the initial goal of any application startup performance investigation is to reduce disk access by reducing the amount of code that is loaded.

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".

感悟人生的甜 2024-08-13 11:04:55

Joshua所说的,加上,看看

What Joshua said, plus, look at the third paragraph of this answer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文