Updated 2010-10-23 11:12:47 by dkf
clock clicks ?-option?

clock clicks returns a high-resolution time value as a system-dependent integer value. See the clock reference page for more detail.

If -milliseconds is provided as an option, then the command is synonymous with clock milliseconds. In 8.5+, clicks -milliseconds is deprecated.

If -microseconds is provided as an option, then the command is synonymous with clock microseconds. In 8.5+, clicks -microseconds is deprecated. -microseconds doesn't exist in 8.4.

In Classic MacOS, the clicks were typically as long as 1/60 second, but in recent MacOS X, they are instead so fast that
  expr {[clock clicks] == [clock clicks]}

never seems to return true (more than µs resolution). Other platforms still have had clicks = milliseconds, and this assumption is sometimes made in Tcl code, which can lead to bugs that don't show up on all platforms.

In other words, the uniqueness of this value is often high but notoriously unreliable, especially for cross-platform comparisons. An alternative source when generating unique IDs (cf. GUID and UUID) is info cmdcount.

Scott Beasley: I feel that info cmdcount is totally useless for Unique key generation. It stays very small in size for too long and changes at a MUCH lower rate then does clock clicks in a modern tcl (8.4-8.5) system. Not saying it couldn't be used as an "enhancement" number though in the generation process.

Lars H: Why is it a problem to be small? The need (as I understand it) is for uniqueness of values, not for having them look random.

Scott Beasley: A uuid is 128 bits. You need enough in terms of size and variation to generate one. I do see the value of info cmdcount in combination with clock clicks on older systems. I may look into that for my needs as well and publish my results.

Lars H: OK, so essentially a randomness argument — I'm generating these things, others are too, and we want to be reasonably sure there won't be a collision. Not all unique-IDs are supposed to be "universally" unique however, many just need to be locally unique.