Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

clock clicks on Solaris 9

21 views
Skip to first unread message

jjm...@gmail.com

unread,
Nov 14, 2005, 4:14:18 PM11/14/05
to
What measure of time is returned by clock clicks on Solaris 9?

Robert Hicks

unread,
Nov 14, 2005, 7:09:05 PM11/14/05
to
jjm...@gmail.com wrote:
> What measure of time is returned by clock clicks on Solaris 9?

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

jjm...@gmail.com

unread,
Nov 14, 2005, 9:06:11 PM11/14/05
to
I am using clock clicks without any further arguments on Solaris 9.
Should I assume millisecond?

Don Porter

unread,
Nov 14, 2005, 9:34:48 PM11/14/05
to
jjm...@gmail.com wrote:
> I am using clock clicks without any further arguments on Solaris 9.
> Should I assume millisecond?

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 |
|______________________________________________________________________|

Robert Hicks

unread,
Nov 14, 2005, 9:37:28 PM11/14/05
to
"Unlike clock seconds and clock milliseconds, the value of clock clicks
is not guaranteed to be tied to any fixed epoch; it is simply intended
to be the most precise interval timer available, and is intended only
for relative timing studies such as benchmarks."

I would say if you want milliseconds the [clock milliseconds] is what
you want to use.

Robert

Robert Hicks

unread,
Nov 14, 2005, 9:43:52 PM11/14/05
to
Oops...sorry that was 8.5 syntax. For 8.4 you should do:

clock clicks -milliseconds

jjm...@gmail.com

unread,
Nov 14, 2005, 11:10:59 PM11/14/05
to
Thank you very much for all the feedback. Sadly I am forced to use an
EXTREMELY old version of the Tcl interpreter, 8.0, that does not
support -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

Don Porter

unread,
Nov 14, 2005, 11:21:24 PM11/14/05
to
jjm...@gmail.com wrote:
> 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.

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;

Fredderic

unread,
Nov 15, 2005, 7:11:33 AM11/15/05
to
On 14 Nov 2005 20:10:59 -0800,
"jjm...@gmail.com" <jjm...@gmail.com> wrote:

> 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

jjm...@gmail.com

unread,
Nov 15, 2005, 2:25:57 PM11/15/05
to
So in your example dividing the number of clicks by 1000 would yield
millisecond?

0 new messages