Version 12 of Time

Updated 2008-01-04 09:38:38 by joker

http://www.tcl.tk/man/tcl8.4/TclCmd/time.htm

Does anyone have some examples of using Tcl's time command? time executes script one time, or optionally, iterations times,

 time {myCommand $arg1 $arg2} 1000

will run the specified command, with substitutions performed, 1000 times, and finally return a list like this:

The higher you give the factor, the more precise the measurement will be, but of course take proportional time - so best start with small values, and increase until it feels too slow.

See How to measure Performance for additional info - but no obvious examples. More iterations increase the precision of the returned value, at the cost of


Also another use of the word time is as a network protocol for the transmission of time data - see RFC868 [L1 ] NTP is a more sophisticated protocol, but the time protocol does a simple job simply.


In yet another different use of the word time, LV asks "Has anyone written a time chooser similar to the date chooser widgets written elsewhere on the Wiki?" Larry refers to A little date chooser and An i15d date chooser. You can measure the runtime of a lengthy script with the following pattern: You might like to check out: timeentry and timefield.


 set t0 [clock clicks -millisec]
 ...
 ...
 puts stderr "[expr ([clock clicks -millisec]-$t0)/1000.] sec" ;# RS

Even when you're not interested in the timing, you can use time as a simple control structure for loops:

 time {puts Hello} 5

 for {set i 0} {$i<5} {incr i} {puts Hello}

Tcl syntax help - Arts and crafts of Tcl-Tk programming - Category Command - Category Performance - Category Internet