2009-09-22 5 views
4

DOS 프롬프트에서 스크립트 시간을 어떻게 조정합니까?DOS에서 스크립트를 실행하는 방법?

* 표시 괜찬아 equivanlent은 다음과 같습니다이에 DOS의 상당

$ time myscript 

real 0m0.886s 
user 0m0.846s 
sys 0m0.031s 

$ 

있습니까? 감사합니다

+0

당신은 실제로 DOS 또는 Windows 용 명령 셸에 대해 이야기하고 있습니까? –

+1

가능한 [Windows 명령 줄에서 명령 실행 시간을 측정하는 방법?] (http://stackoverflow.com/questions/673523/how-to-measure-execution-time-of-command-in-windows-command) - 라인) – olibre

답변

5

당신은 당신의 배치의 시작과 끝이를 넣을 수 있습니다 :

echo %time% 
+0

내가 생각하는 유일한 방법. +1 – dmityugov

+1

경고 : 두 명령의 확장이 명령이 실행되기 전에 완료되기 때문에 명령 ('echo % time % & myprog & echo % time %')에서 직접 사용하지 마십시오. –

3

이 그냥 echo %time%을하는 것이 아니라 당신을위한 시간 차이를 계산하는 DOS 배치 스크립트입니다.

"시간 초과 사용자 섹션"이 실행되는 데 24 시간 이상 걸리지 않는 한 다음 코드는 정상적으로 작동합니다. 용서 또는 제게 제안을 해주십시오. 진행중인 작업으로 약 1 시간을 보냈습니다.

"PAUSE"를 스크립트 호출로 바꾸어 코드 작성 시간을 단축하십시오.

DOS의 BAT 파일은 다음과 같습니다

참고 : 앞에 0이 아니라 소수보다 진수 인 상태 문제를 해결하기 위해 편집되었다.

참고 : "자정"이상의 랩 어라운드를 처리하고 선행 0을 출력에 편집하도록 편집되었습니다.

@echo off 
@rem -------------------------------------------- 
setlocal ENABLEEXTENSIONS 

set start_time=%time% 
echo Beginning at: %start_time% 
echo Running Timed Batch File 
echo. 

@rem echo %* <-- Extension for all args -- easier than following line 
@rem echo %0 %1 %2 %3 %4 %5 %6 %7 %8 %9 ... ... 

@rem DO YOUR WORK HERE -- see "call"/PAUSE is here to "fake" work 
@rem call userscript.bat %* 
PAUSE 

set stop_time=%time% 
echo. 
echo Timed Batch File Completed 
echo Start time: %start_time% 
echo Stop time : %stop_time% 


set TEMPRESULT=%start_time:~0,2% 
call:FN_REMOVELEADINGZEROS 
set start_hour=%TEMPRESULT% 
@rem 
set TEMPRESULT=%start_time:~3,2% 
call:FN_REMOVELEADINGZEROS 
set start_min=%TEMPRESULT% 
@rem 
set TEMPRESULT=%start_time:~6,2% 
call:FN_REMOVELEADINGZEROS 
set start_sec=%TEMPRESULT% 
@rem 
set TEMPRESULT=%start_time:~9,2% 
call:FN_REMOVELEADINGZEROS 
set start_hundredths=%TEMPRESULT% 

set TEMPRESULT=%stop_time:~0,2% 
call:FN_REMOVELEADINGZEROS 
set stop_hour=%TEMPRESULT% 
@rem 
set TEMPRESULT=%stop_time:~3,2% 
call:FN_REMOVELEADINGZEROS 
set stop_min=%TEMPRESULT% 
@rem 
set TEMPRESULT=%stop_time:~6,2% 
call:FN_REMOVELEADINGZEROS 
set stop_sec=%TEMPRESULT% 
@rem 
set TEMPRESULT=%stop_time:~9,2% 
call:FN_REMOVELEADINGZEROS 
set stop_hundredths=%TEMPRESULT% 

set /A start_total=(((((%start_hour%*60)+%start_min%)*60)+%start_sec%)*100)+%start_hundredths% 
set /A stop_total=(((((%stop_hour%*60)+%stop_min%)*60)+%stop_sec%)*100)+%stop_hundredths% 

set /A total_time=%stop_total% - %start_total% 

set /A total_hundredths=%total_time% %% 100 
set total_hundredths=00%total_hundredths% 
set total_hundredths=%total_hundredths:~-2% 
set /A total_time=%total_time%/100 

set /A total_sec="%total_time% %% 60" 
set total_sec=00%total_sec% 
set total_sec=%total_sec:~-2% 
set /A total_time=%total_time%/60 

set /A total_min="%total_time% %% 60" 
set total_min=00%total_min% 
set total_min=%total_min:~-2% 
set /A total_time=%total_time%/60 

set /A total_hour="%total_time% %% 60" 
@rem Handle if it wrapped around over midnight 
if "%total_hour:~0,1%"=="-" set /A total_hour=%total_hour% + 24 

echo Total time: %total_hour%:%total_min%:%total_sec%.%total_hundredths% 

@rem -------------------------------------------- 
@rem Exit the BAT Program 
endlocal 
goto END 

@rem -------------------------------------------- 
@rem FN_REMOVELEADINGZEROS function 
@rem Used to remove leading zeros from Decimal 
@rem numbers so they are not treated as Octal. 
:FN_REMOVELEADINGZEROS 
if "%TEMPRESULT%"=="0" goto END 
if "%TEMPRESULT:~0,1%" NEQ "0" goto END 
set TEMPRESULT=%TEMPRESULT:~1% 
goto FN_REMOVELEADINGZEROS 

@rem -------------------------------------------- 
@rem BAT PROGRAM/FUNCTION FILE EXIT 
:END 
5

Windows Server 2003 Resource Kit에서 timeit.exe를 사용할 수 있습니다. 또한 다른 유용한 도구와 Unix 명령 포트에 대한 정보를 얻을 수 있습니다.

C:\Documents and Settings\Rob>timeit sleep 3 

Version Number: Windows NT 5.1 (Build 2600) 
Exit Time:  2:40 pm, Thursday, December 10 2009 
Elapsed Time:  0:00:03.296 
Process Time:  0:00:00.015 
System Calls:  7576 
Context Switches: 1974 
Page Faults:  1072 
Bytes Read:  6172 
Bytes Written: 11086 
Bytes Other:  144432 
+0

이 접근법은 나에게 가장 어려운 것이었다. 나는 c : \ windows \ system32에있는 dos 배치 파일을 타이밍을 잡았다. 시간을내어 보려고했는데 시스템 경로에 있더라도 .bat에 대한 정규화 된 경로를 입력해야했습니다. – buzz3791

0

당신이 Gammadyne에서 timer.exe이 매우 유용합니다, 도움을 타사 EXE를 사용하여 상관 없어.

setlocal ENABLEEXTENSIONS 
FOR /F %%G IN ('timer') DO SET start_time=%%G 

@rem Do your work Here 
call userscript.bat %* 

timer %start_time% "Total time" 
endlocal 
관련 문제