clock clicks ?-milliseconds?
Return a high-resolution time value as a system-dependent integer
value. The unit of the value is system-dependent but should be the
highest resolution clock available on the system such as a CPU cycle
counter. If -milliseconds is specified, then the value is guaranteed to
be of millisecond granularity. This value should only be used for the
relative measurement of elapsed time.
All about "clock": http://tmml.sourceforge.net/doc/tcl/clock.html
HTH
Robert
No.
If you want millisecond granularity, you should add the -milliseconds
switch to your command invocation.
Or you should just use [clock clicks] return value as a relative time
counter of undefined granularity.
--
| Don Porter Mathematical and Computational Sciences Division |
| donald...@nist.gov Information Technology Laboratory |
| http://math.nist.gov/~DPorter/ NIST |
|______________________________________________________________________|
I would say if you want milliseconds the [clock milliseconds] is what
you want to use.
Robert
clock clicks -milliseconds
The value I receive when substracting t1 - t0 each set as follows:
set t0 [ clock clicks ]
se t1 [ clock clicks ]
set elapsed [ expr $t1 - $t0 ]
is 12977? Again I am running on Solaris 9, so I am not really sure
what this number represents.
John
It means a longer amount of time than 12000 and a smaller amount
of time than 14000. The exact granularity of [clock clicks] in
Tcl 8.0 is intentionally left undefined. That's the official answer.
For more unofficial things, an examination of the source code is
in order. For Solaris 9, you'll get:
unsigned long
TclpGetClicks()
{
unsigned long now;
#ifdef NO_GETTOD
struct tms dummy;
#else
struct timeval date;
struct timezone tz;
#endif
#ifdef NO_GETTOD
now = (unsigned long) times(&dummy);
#else
gettimeofday(&date, &tz);
now = date.tv_sec*1000000 + date.tv_usec;
#endif
return now;
> set t0 [ clock clicks ]
> se t1 [ clock clicks ]
> set elapsed [ expr $t1 - $t0 ]
> is 12977? Again I am running on Solaris 9, so I am not really sure
> what this number represents.
On my system, one second is represented by 1000000 clock clicks.
I tested that with this little snippet of code:
set junk [clock scan "2 second"];while { [clock seconds] < $junk } {set
t0 [clock clicks]};incr junk;while { [clock seconds] < $junk } {set t1
[clock clicks]};expr $t1 - $t0
If anyone see's a flaw in that, let me know. There's probably a better
way of doing it, but that seems to work quite well. It gave me exactly
1000000 several times in a row.
The piece [expr 0 - ( [clock clicks] - [clock clicks] )] yields 15's
and 16's usually on my machine. What I don't understand, is why I get
a very consistent -17 if I wake away the subtraction from zero. Why is
it that a little extra maths makes the expression run "one click
FASTER"?
Fredderic