From: Joe English on 2 Aug 2010 17:40 Aric Bills wrote: > Ahmad asked: >> I use [clock clicks] at the start and end to get time stamps. >> Then, I use: run_time [expr {$end - $start}] >> But result is not human meaningful. >> How to convert it to a format like: hours : mins : seconds : >> milliseconds �? > > According to the clock man page, [clock clicks] is platform- > dependent. If you want milliseconds instead, try [clock > milliseconds]; if you want microseconds, try [clock microseconds]. And if (as I suspect) you want seconds, try [clock seconds]. You might also find the following useful: proc format-elapsed {sec} { set s [expr {$sec % 60}] ; set rem [expr {$sec / 60}] set m [expr {$rem % 60}] ; set rem [expr {$rem / 60}] set h $rem return [format "%02d:%02d:%02d" $h $m $s] } proc tick {} { variable starttime set starttime [clock seconds] } proc tock {} { variable starttime return [format-elapsed [expr {[clock seconds] - $starttime}]] } Sample usage: tick; # ... some long-running process ... puts "Elapsed time: [tock]" --JE
|
Pages: 1 Prev: Project announce: Porting gnocl to MacOSX Next: I GOT $2500 FROM PAYPAL.... |