Windows 下的基准测试
在大多数类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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从命令行(低分辨率,可能不准确): 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
如果您想要毫秒级的精度(相当于 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. includemmsystem.h
and link againstwinmm.lib
. However, all this would just give you a time value, you'd either need to put in asystem()
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.我也在 Windows 中使用“时间”实用程序。自带mingw+msys。
I use the 'time' utility in windows too. It comes with mingw+msys.