Windows 下的基准测试

发布于 2024-10-13 01:33:27 字数 130 浏览 6 评论 0原文

在大多数类Unix系统下,你可以使用“time”命令来执行一个程序并告诉你它使用了多少空间和时间。有人知道 Windows 上有什么类似的东西吗?

(不,我并不是特别想为了这个而花 6 个月的时间学习 Win32 API...)

Under most Unix-like systems, you can use the "time" command to execute a program and tell you how much space and time it used. Does anybody know of anything comparable for Windows?

(No, I don't particularly want to spend 6 months learning the Win32 API just for this...)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

伴我心暖 2024-10-20 01:33:27

从命令行(低分辨率,可能不准确): echo %date% %time%

以编程方式:QueryPerformanceCounter。 http://msdn.microsoft.com/en-我们/library/ms644904(v=vs.85).aspx

From the command line (low resolution, possibly inaccurate): echo %date% %time%

Programmatically: QueryPerformanceCounter. http://msdn.microsoft.com/en-us/library/ms644904(v=vs.85).aspx

笑忘罢 2024-10-20 01:33:27

如果您想要毫秒级的精度(相当于 linux/unix time 给您的精度),那么 timeGetTime() 是您所需要的。它返回自系统启动以来的毫秒数。包含 mmsystem.h 并链接到 winmm.lib。但是,所有这些只会给您一个时间值,您要么需要在其间放入 system() 调用,要么执行诸如在调用时将开始超时转储到文件之类的操作读第一遍,然后读第二遍。

更实用的解决方案,根据您的具体情况可能会更有用:

  • 编写一个批处理脚本来调用您希望进行基准测试的程序并将其包装起来,以便将其写入文件:

    回显“开始”>>日志.txt
    do_my_stuff.exe
    回显“停止”>>日志.txt

    然后使用优秀的工具LogExpert来查看时间戳

  • 安装cygwin 工具并使用它附带的time。如果您只需要在自己的机器上执行此操作,并且基准测试程序不需要复杂的设置(命令行参数、环境变量等),那么这可能是最简单的方法。

If you want something of the order of millisecond accuracy (which is comparable to what the linux/unix time would give you) then timeGetTime() is what you need. It returns the number of milliseconds since the system was booted. include mmsystem.h and link against winmm.lib. However, all this would just give you a time value, you'd either need to put in a system() call in between or do something like dump the start time out to a file when called for the first time, and then read it the second time.

More pragmatic solutions, which may be more useful depending on your circumstances:

  • Write a batch script to call the program you wish you benchmark and wrap it so that it writes to a file:

    echo "start" >> log.txt
    do_my_stuff.exe
    echo "stop" >> log.txt

    and then use a tool as the excellent LogExpert to look at the timestamps

  • Install the cygwin tools and use the time that comes with that. If you only need to do this on your own machine, and the benchmark program doesn't require complex setting up (command line parameters, environment variables, etc) then this may be the easiest approach.

臻嫒无言 2024-10-20 01:33:27

我也在 Windows 中使用“时间”实用程序。自带mingw+msys。

I use the 'time' utility in windows too. It comes with mingw+msys.

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