2016-09-27 2 views

답변

0

티클 자체를하지 않는 완전한 TCL 스크립트에 의해 촬영 CPU 시간을 측정하는 올바른 방법입니다 확실하지 않다 이 정보를 제공하십시오. TclX 패키지의 times 명령을 사용하려고합니다.

package require Tclx 

set pre [times] 
# do CPU intensive operation here; for example calculating the length of a number with many digits... 
string length [expr {13**12345}] 
set post [times] 

# the current process's non-OS CPU time is the first element; it's in milliseconds 
set cpuSecondsTaken [expr {([lindex $post 0] - [lindex $pre 0])/1000.0}] 
# The other elements are: system-cpu-time, subprocess-user-cpu-time, subprocess-system-time 

물론이 정보를 정확하게 측정하는 OS에 의존하고 있습니다. TWAPI 패키지에서 논리적으로 유사한 것이있을지라도 POSIX가 아닌 시스템 (예 : Windows)에는 이식 할 수 없습니다.

+0

때로는 셸 명령'time'을 사용하여 Tcl에 대한 호출을 래핑하는 것이 더 쉽습니다. 그것은 조잡한 측정을 위해 충분히 잘 작동합니다. –

관련 문제