2016-09-27 42 views
1

私は長いTCLスクリプトを持っています。私は、Tcl自体にはない完全なTCLスクリプトで撮影した私はTCLでtimeコマンドを試してみましたが、私はそれがCPU時間を測定することが正しい方法であることを確認していないTCLスクリプトのCPU時間を測定する方法

TCL

にプロセスを取っている正確なCPU時間を計測

答えて

0

たいこの情報を提供してください。 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への呼び出しをラップする方が簡単な場合もあります。これは、粗測定で十分機能します。 –

関連する問題