如何使用Windows批处理文件来衡量控制台应用程序的性能? [英] How can I use a Windows batch file to measure the performance of console application?

查看:144
本文介绍了如何使用Windows批处理文件来衡量控制台应用程序的性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何写一个简单的批处理文件来衡量一个基于控制台的应用程序的性能?控制台应用程序接受两个命令行参数。

How can I write a simple batch file to measure the performance of a console-based application? The console application accepts two command line arguments.

我想获得:

StartTime = System Dos time
myconsoleapp arg1, arg2
StopTime = System Dos Time
timeDelta = stoptime - starttime

我会写的timeDelta到控制台上的一个文件或显示。

I would write the timeDelta to a file or display on the console.

推荐答案

一个纯粹的一批解决方案可以。

A pure batch solution could be.

@echo off
set "startTime=%time%"
for /L %%n in (1,1, 1000) do <nul set /p "="
set "stopTime=%time%"
call :timeDiff diff startTime stopTime
echo %diff% milli seconds
goto :eof

:timeDiff
setlocal
call :timeToMS time1 "%~2"
call :timeToMS time2 "%~3"
set /a diff=time2-time1
(
  ENDLOCAL
  set "%~1=%diff%"
  goto :eof
)

:timeToMS
::### WARNING, enclose the time in " ", because it can contain comma seperators
SETLOCAL EnableDelayedExpansion
FOR /F "tokens=1,2,3,4 delims=:,.^ " %%a IN ("!%~2!") DO (
  set /a "ms=(((30%%a%%100)*60+7%%b)*60+3%%c-42300)*1000+(1%%d0 %% 1000)"
)
(
  ENDLOCAL
  set %~1=%ms%
  goto :eof
)

这篇关于如何使用Windows批处理文件来衡量控制台应用程序的性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆