Performance Tuning

The time command measures the execution time of a Tcl command. It takes an optional parameter that is a repetition count:

						time {set a "Hello, World!"}1000
=> 28 microseconds per iteration
					

If you need the result of the command being timed, use set to capture the result:

puts $log "command: [time {set result [command]}]"

Time stamps in a Log

Another way to gain insight into the performance of your script is to generate log records that contain time stamps. The clock seconds value is too coarse, but you can couple it with the clock clicks value to get higher resolution measurements. Use the code shown in Example 13-1 on page 175 to calibrate the clicks per second on your system. Example 13-13 writes log records that contain ...

Get Practical Programming in Tcl & Tk, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.