2016-09-27 35 views
1

我有很長的TCL腳本。我想測量精確CPU時間的進程正在以TCL如何測量TCL腳本的CPU時間

我試着在TCL的時間命令,但我不知道它是衡量CPU時間,正確的方式,通過完整的TCL腳本採取

回答

0

的Tcl本身不提供這些信息。你想使用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 

您當然是依賴於操作系統來正確測量這些信息。雖然在TWAPI包中可能有些邏輯上相似的東西,但它不適用於非POSIX系統(例如Windows)。

+0

有時,使用shell命令'time'來包裝對Tcl的調用會更容易。這對於原油測量來說工作得很好。 –