민서네집

[batch] console 프로그램 실행시간 구하기 본문

프로그래밍

[batch] console 프로그램 실행시간 구하기

브라이언7 2018. 1. 6. 14:14

[batch] console 프로그램 실행시간 구하기


[출처] https://code.i-harness.com/en/q/b4916


@echo off
setlocal

rem Remeber start time. Note that we don't look at the date, so this
rem calculation won't work right if the program run spans local midnight.
set t0=%time: =0%

rem do something here.... but probably with more care about quoting.
rem specifically, odd things will happen if any arguments contain 
rem precent signs or carets and there may be no way to prevent it.
call %*

rem Capture the end time before doing anything else
set t=%time: =0%

rem make t0 into a scaler in 100ths of a second, being careful not 
rem to let SET/A misinterpret 08 and 09 as octal
set /a h=1%t0:~0,2%-100
set /a m=1%t0:~3,2%-100
set /a s=1%t0:~6,2%-100
set /a c=1%t0:~9,2%-100
set /a starttime = %h% * 360000 + %m% * 6000 + 100 * %s% + %c%

rem make t into a scaler in 100ths of a second
set /a h=1%t:~0,2%-100
set /a m=1%t:~3,2%-100
set /a s=1%t:~6,2%-100
set /a c=1%t:~9,2%-100
set /a endtime = %h% * 360000 + %m% * 6000 + 100 * %s% + %c%

rem runtime in 100ths is now just end - start
set /a runtime = %endtime% - %starttime%
set runtime = %s%.%c%

echo Started at %t0%
echo Ended   at %t%
echo Ran for %runtime%0 ms


나는 위와 같이 timer.bat 파일을 만들었다.

원문과 달라진 부분은 call 명령어를 써서 배치 파일을 호출하고 나서 계속 실행되도록 한 점과 Ended at ... 으로 종료 시각까지 표시해 준 점이다.


'프로그래밍' 카테고리의 다른 글

Private Git Repository  (0) 2018.01.10
[batch] sleep 배치파일 만들기  (0) 2018.01.06
User agent 를 분석하는 API  (0) 2017.08.03
plotly  (0) 2016.12.05
Udemy Assembly 강의  (0) 2016.12.05
Comments