TABLE OF CONTENTS
::pwtk::measure_time
SYNOPSIS
proc ::pwtk::measure_time {args} {
USAGE
::pwtk::measure_time ?-fmt FORMAT? script ?stdoutRedirectFile?
PURPOSE
Time the execution of a script. This routine is very similar to the Tcl 'time' command, but provides more descriptive printout and reports time in seconds. It is intended for scripts, such as calculations, which take long time.
OPTION
- -fmt FORMAT ... format of the printed time (in C syntax, default = %.3f)
ARGUMENTS
- script ... script to time its execution
- stdoutRedirectFile ... (optional) if given, it is the name of the file to which stdout of the script is redirected to
SOURCE
set nargmin 1 set nargmax 2 set usage "?-fmt FORMAT? script ?stdoutRedirectFile?" set options { {fmt.arg %.3f "format (precision) of the reported time in seconds"} } parseOpt_ lassign $args script stdoutRedirectFile print TIME "Timing the execution of a script:" print "\n[string trim $script \n]\n" if { $stdoutRedirectFile ne {} } { infoMsg "stdout redirected to a log file : $stdoutRedirectFile" } print "Executing script at [clock format [clock seconds]]" set t0 [clock milliseconds] if { $stdoutRedirectFile eq {} } { uplevel $script } else { uplevel ::pwtk::redirect_stdout_to $stdoutRedirectFile $script } set t [clock milliseconds] print "Script execution finished at [clock format [clock seconds]]\n" set dt [format $opt(fmt) [pwtk::time2s -r [expr $t - $t0]ms ]] print "Time needed to execute the script: $dt seconds\n" return $dt }