Posted By

Phoenicia7 on 05/14/12


Tagged


Versions (?)

Elapsed Time


 / Published in: TCL
 

  1. proc _elapsedTime { start end } {
  2. # Procedure to measure the time elapsed.
  3. # Arguments are two points in time measured in seconds.
  4. # Use as follows:
  5. # set start [clock seconds]
  6. # set end [clock seconds]
  7. # _elapsed_time $start $end
  8.  
  9. set total_seconds [expr $end - $start]
  10. set _hours [expr int($total_seconds/3600)]
  11. set _minutes [expr int(($total_seconds % 3600)/60)]
  12. set _seconds [expr int(($total_seconds % 60))]
  13. if {$_hours == 1} {set htxt hour} else {set htxt hours}
  14. if {$_minutes == 1} {set mtxt minute} else {set mtxt minutes}
  15. if {$_seconds == 1} {set stxt second} else {set stxt seconds}
  16. if {$_hours == 0} {
  17. if {$_minutes == 0} {
  18. return "$_seconds $stxt"
  19. } else {
  20. return "$_minutes $mtxt $_seconds $stxt"
  21. }
  22. } else {
  23. return "$_hours $htxt $_minutes $mtxt $_seconds $stxt"
  24. }
  25. }
  26.  

Report this snippet  

You need to login to post a comment.