Attachment "clock.patch" to
ticket [991742ffff]
added by
rmax
2004-07-16 00:12:35.
0000: 2d 2d 2d 20 64 6f 63 2f 63 6c 6f 63 6b 2e 6e 09 --- doc/clock.n.
0010: 32 34 20 4d 61 79 20 32 30 30 34 20 32 33 3a 33 24 May 2004 23:3
0020: 31 3a 34 32 20 2d 30 30 30 30 09 31 2e 31 37 0a 1:42 -0000.1.17.
0030: 2b 2b 2b 20 64 6f 63 2f 63 6c 6f 63 6b 2e 6e 09 +++ doc/clock.n.
0040: 31 35 20 4a 75 6c 20 32 30 30 34 20 31 37 3a 30 15 Jul 2004 17:0
0050: 36 3a 30 38 20 2d 30 30 30 30 0a 40 40 20 2d 33 6:08 -0000.@@ -3
0060: 35 2c 32 37 20 2b 33 35 2c 31 36 20 40 40 0a 20 5,27 +35,16 @@.
0070: 74 69 6d 65 20 76 61 6c 75 65 20 61 73 20 61 20 time value as a
0080: 73 79 73 74 65 6d 2d 64 65 70 65 6e 64 65 6e 74 system-dependent
0090: 20 69 6e 74 65 67 65 72 20 76 61 6c 75 65 2e 20 integer value.
00a0: 20 54 68 65 20 75 6e 69 74 20 6f 66 20 74 68 65 The unit of the
00b0: 20 76 61 6c 75 65 0a 20 69 73 20 73 79 73 74 65 value. is syste
00c0: 6d 2d 64 65 70 65 6e 64 65 6e 74 20 62 75 74 20 m-dependent but
00d0: 73 68 6f 75 6c 64 20 62 65 20 74 68 65 20 68 69 should be the hi
00e0: 67 68 65 73 74 20 72 65 73 6f 6c 75 74 69 6f 6e ghest resolution
00f0: 20 63 6c 6f 63 6b 20 61 76 61 69 6c 61 62 6c 65 clock available
0100: 0a 20 6f 6e 20 74 68 65 20 73 79 73 74 65 6d 20 . on the system
0110: 73 75 63 68 20 61 73 20 61 20 43 50 55 20 63 79 such as a CPU cy
0120: 63 6c 65 20 63 6f 75 6e 74 65 72 2e 20 0a 2d 2e cle counter. .-.
0130: 54 50 0a 2b 0a 20 2e 56 53 20 38 2e 35 0a 20 49 TP.+. .VS 8.5. I
0140: 66 20 74 68 65 20 5c 66 49 6f 70 74 69 6f 6e 5c f the \fIoption\
0150: 66 52 20 61 72 67 75 6d 65 6e 74 20 69 73 20 5c fR argument is \
0160: 66 42 5c 2d 6d 69 6c 6c 69 73 65 63 6f 6e 64 73 fB\-milliseconds
0170: 5c 66 52 2c 20 74 68 65 6e 20 74 68 65 20 76 61 \fR, then the va
0180: 6c 75 65 20 69 73 0a 20 67 75 61 72 61 6e 74 65 lue is. guarante
0190: 65 64 20 74 6f 20 62 65 20 61 6e 20 61 70 70 72 ed to be an appr
01a0: 6f 78 69 6d 61 74 65 20 63 6f 75 6e 74 20 6f 66 oximate count of
01b0: 20 6d 69 6c 6c 69 73 65 63 6f 6e 64 73 20 72 65 milliseconds re
01c0: 74 75 72 6e 65 64 20 61 73 0a 20 61 20 77 69 64 turned as. a wid
01d0: 65 20 69 6e 74 65 67 65 72 3b 20 74 68 65 20 72 e integer; the r
01e0: 75 6c 65 20 73 68 6f 75 6c 64 0a 20 61 6c 77 61 ule should. alwa
01f0: 79 73 20 68 6f 6c 64 20 74 68 61 74 20 5c 66 42 ys hold that \fB
0200: 63 6c 6f 63 6b 20 63 6c 69 63 6b 73 20 2d 6d 69 clock clicks -mi
0210: 6c 6c 69 73 65 63 6f 6e 64 73 5c 66 52 20 64 69 lliseconds\fR di
0220: 76 69 64 65 64 20 62 79 20 31 30 30 30 20 69 73 vided by 1000 is
0230: 20 74 68 65 0a 20 73 61 6d 65 20 61 73 20 5c 66 the. same as \f
0240: 42 63 6c 6f 63 6b 20 73 65 63 6f 6e 64 73 5c 66 Bclock seconds\f
0250: 52 2e 0a 2d 2e 54 50 0a 2d 49 74 20 74 68 65 20 R..-.TP.-It the
0260: 5c 66 49 6f 70 74 69 6f 6e 5c 66 52 20 61 72 67 \fIoption\fR arg
0270: 75 6d 65 6e 74 20 69 73 20 5c 66 42 2d 6d 69 63 ument is \fB-mic
0280: 72 6f 73 65 63 6f 6e 64 73 5c 66 52 2c 20 74 68 roseconds\fR, th
0290: 65 6e 20 74 68 65 20 76 61 6c 75 65 20 69 73 0a en the value is.
02a0: 2d 67 75 61 72 61 6e 74 65 65 64 20 74 6f 20 62 -guaranteed to b
02b0: 65 20 61 6e 20 61 70 70 72 6f 78 69 6d 61 74 65 e an approximate
02c0: 20 63 6f 75 6e 74 20 6f 66 20 6d 69 63 72 6f 73 count of micros
02d0: 65 63 6f 6e 64 73 20 72 65 74 75 72 6e 65 64 20 econds returned
02e0: 61 73 20 61 20 77 69 64 65 0a 2d 69 6e 74 65 67 as a wide.-integ
02f0: 65 72 3b 20 74 68 65 20 72 75 6c 65 20 73 68 6f er; the rule sho
0300: 75 6c 64 20 68 6f 6c 64 20 74 68 61 74 20 5c 66 uld hold that \f
0310: 42 63 6c 6f 63 6b 20 63 6c 69 63 6b 73 20 2d 6d Bclock clicks -m
0320: 69 63 72 6f 73 65 63 6f 6e 64 73 5c 66 52 0a 2d icroseconds\fR.-
0330: 64 69 76 69 64 65 64 20 62 79 20 31 30 30 30 20 divided by 1000
0340: 69 73 20 74 68 65 20 73 61 6d 65 20 61 73 20 5c is the same as \
0350: 66 42 63 6c 6f 63 6b 20 63 6c 69 63 6b 73 20 2d fBclock clicks -
0360: 6d 69 6c 6c 69 73 65 63 6f 6e 64 73 5c 66 52 2e milliseconds\fR.
0370: 0a 2d 2e 54 50 0a 2d 4f 6e 20 73 6f 6d 65 20 68 .-.TP.-On some h
0380: 61 72 64 77 61 72 65 2c 20 74 68 65 20 63 6f 75 ardware, the cou
0390: 6e 74 73 20 6f 66 20 6d 69 6c 6c 69 73 65 63 6f nts of milliseco
03a0: 6e 64 73 20 61 6e 64 20 6d 69 63 72 6f 73 65 63 nds and microsec
03b0: 6f 6e 64 73 20 6d 61 79 20 64 69 76 65 72 67 65 onds may diverge
03c0: 0a 2d 66 72 6f 6d 20 74 68 65 20 73 79 73 74 65 .-from the syste
03d0: 6d 20 63 6c 6f 63 6b 20 66 6f 72 20 73 68 6f 72 m clock for shor
03e0: 74 20 70 65 72 69 6f 64 73 3b 20 74 68 65 20 72 t periods; the r
03f0: 65 61 73 6f 6e 20 69 73 20 74 68 61 74 20 74 68 eason is that th
0400: 65 79 20 63 61 6e 0a 2d 62 65 20 64 65 72 69 76 ey can.-be deriv
0410: 65 64 20 66 72 6f 6d 20 64 69 66 66 65 72 65 6e ed from differen
0420: 74 20 73 6f 75 72 63 65 73 2c 20 61 6e 64 20 61 t sources, and a
0430: 20 63 6f 6d 70 6c 65 78 20 70 72 6f 63 65 64 75 complex procedu
0440: 72 65 20 69 73 20 72 65 71 75 69 72 65 64 0a 2d re is required.-
0450: 74 6f 20 63 61 6c 69 62 72 61 74 65 20 74 68 65 to calibrate the
0460: 6d 2e 20 20 4d 6f 72 65 6f 76 65 72 2c 20 54 63 m. Moreover, Tc
0470: 6c 20 6d 61 6b 65 73 20 61 6e 20 65 66 66 6f 72 l makes an effor
0480: 74 20 6e 65 76 65 72 20 74 6f 20 68 61 76 65 20 t never to have
0490: 74 68 65 20 63 6c 6f 63 6b 0a 2d 6c 65 61 70 20 the clock.-leap
04a0: 66 6f 72 77 61 72 64 20 6e 6f 72 20 61 70 70 65 forward nor appe
04b0: 61 72 20 74 6f 20 72 75 6e 20 62 61 63 6b 77 61 ar to run backwa
04c0: 72 64 2c 20 70 72 65 66 65 72 72 69 6e 67 20 69 rd, preferring i
04d0: 6e 73 74 65 61 64 20 74 6f 20 73 6c 6f 77 20 6f nstead to slow o
04e0: 72 0a 2d 73 70 65 65 64 20 75 70 20 74 68 65 20 r.-speed up the
04f0: 63 6c 6f 63 6b 20 66 72 65 71 75 65 6e 63 79 20 clock frequency
0500: 73 6c 69 67 68 74 6c 79 20 75 6e 74 69 6c 20 69 slightly until i
0510: 74 27 73 20 62 61 63 6b 20 69 6e 20 73 79 6e 63 t's back in sync
0520: 68 72 6f 6e 69 7a 61 74 69 6f 6e 2e 0a 2d 46 6f hronization..-Fo
0530: 72 20 74 68 69 73 20 72 65 61 73 6f 6e 2c 20 6d r this reason, m
0540: 6f 73 74 20 54 63 6c 20 70 72 6f 67 72 61 6d 6d ost Tcl programm
0550: 65 72 73 20 6e 65 65 64 20 6e 65 76 65 72 20 77 ers need never w
0560: 6f 72 72 79 20 61 62 6f 75 74 20 73 75 63 68 0a orry about such.
0570: 2d 70 68 65 6e 6f 6d 65 6e 61 20 61 73 20 6c 65 -phenomena as le
0580: 61 70 20 73 65 63 6f 6e 64 73 2e 0a 2b 0a 2b 54 ap seconds..+.+T
0590: 68 65 20 5c 66 42 2d 6d 69 6c 6c 69 73 65 63 6f he \fB-milliseco
05a0: 6e 64 73 5c 66 52 20 6f 70 74 69 6f 6e 20 69 73 nds\fR option is
05b0: 20 64 65 70 72 65 63 61 74 65 64 20 61 6e 64 20 deprecated and
05c0: 6d 61 79 20 62 65 20 72 65 6d 6f 76 65 64 20 69 may be removed i
05d0: 6e 20 61 0a 2b 66 75 74 75 72 65 20 76 65 72 73 n a.+future vers
05e0: 69 6f 6e 2e 20 55 73 65 20 5c 66 42 63 6c 6f 63 ion. Use \fBcloc
05f0: 6b 20 6d 69 6c 6c 69 73 65 63 6f 6e 64 73 5c 66 k milliseconds\f
0600: 52 20 69 6e 73 74 65 61 64 2e 0a 20 2e 56 45 20 R instead.. .VE
0610: 38 2e 35 0a 20 2e 54 50 0a 20 5c 66 42 63 6c 6f 8.5. .TP. \fBclo
0620: 63 6b 20 66 6f 72 6d 61 74 20 5c 66 49 63 6c 6f ck format \fIclo
0630: 63 6b 56 61 6c 75 65 5c 66 52 20 3f 5c 66 42 5c ckValue\fR ?\fB\
0640: 2d 66 6f 72 6d 61 74 20 5c 66 49 73 74 72 69 6e -format \fIstrin
0650: 67 5c 66 52 3f 20 3f 5c 66 42 5c 2d 67 6d 74 20 g\fR? ?\fB\-gmt
0660: 5c 66 49 62 6f 6f 6c 65 61 6e 5c 66 52 3f 0a 40 \fIboolean\fR?.@
0670: 40 20 2d 32 37 35 2c 36 20 2b 32 36 34 2c 32 38 @ -275,6 +264,28
0680: 20 40 40 0a 20 75 6e 69 74 20 6f 66 20 74 68 65 @@. unit of the
0690: 20 76 61 6c 75 65 20 69 73 20 73 65 63 6f 6e 64 value is second
06a0: 73 2c 20 61 6c 6c 6f 77 69 6e 67 20 69 74 20 74 s, allowing it t
06b0: 6f 20 62 65 20 75 73 65 64 20 66 6f 72 20 72 65 o be used for re
06c0: 6c 61 74 69 76 65 20 74 69 6d 65 0a 20 63 61 6c lative time. cal
06d0: 63 75 6c 61 74 69 6f 6e 73 2e 20 20 54 68 65 20 culations. The
06e0: 76 61 6c 75 65 20 69 73 20 75 73 75 61 6c 6c 79 value is usually
06f0: 20 64 65 66 69 6e 65 64 20 61 73 20 74 6f 74 61 defined as tota
0700: 6c 20 65 6c 61 70 73 65 64 20 74 69 6d 65 20 66 l elapsed time f
0710: 72 6f 6d 0a 20 61 6e 20 60 60 65 70 6f 63 68 27 rom. an ``epoch'
0720: 27 2e 20 20 59 6f 75 20 73 68 6f 75 6c 64 6e 27 '. You shouldn'
0730: 74 20 61 73 73 75 6d 65 20 74 68 65 20 76 61 6c t assume the val
0740: 75 65 20 6f 66 20 74 68 65 20 65 70 6f 63 68 2e ue of the epoch.
0750: 0a 2b 2e 54 50 0a 2b 5c 66 42 63 6c 6f 63 6b 20 .+.TP.+\fBclock
0760: 6d 69 6c 6c 69 73 65 63 6f 6e 64 73 5c 66 52 0a milliseconds\fR.
0770: 2b 2e 54 50 0a 2b 5c 66 42 63 6c 6f 63 6b 20 6d +.TP.+\fBclock m
0780: 69 63 72 6f 73 65 63 6f 6e 64 73 5c 66 52 0a 2b icroseconds\fR.+
0790: 2e 56 53 20 38 2e 35 0a 2b 52 65 74 75 72 6e 20 .VS 8.5.+Return
07a0: 74 68 65 20 63 75 72 72 65 6e 74 20 64 61 74 65 the current date
07b0: 20 61 6e 64 20 74 69 6d 65 20 61 73 20 61 20 77 and time as a w
07c0: 69 64 65 20 69 6e 74 65 67 65 72 20 63 6f 75 6e ide integer coun
07d0: 74 69 6e 67 20 69 6e 0a 2b 6d 69 6c 6c 69 73 65 ting in.+millise
07e0: 63 6f 6e 64 73 20 6f 72 20 6d 69 63 72 6f 73 65 conds or microse
07f0: 63 6f 6e 64 73 20 72 65 70 65 63 74 69 76 65 6c conds repectivel
0800: 79 2e 0a 2b 0a 2b 54 68 65 20 72 75 6c 65 20 73 y..+.+The rule s
0810: 68 6f 75 6c 64 20 61 6c 77 61 79 73 20 68 6f 6c hould always hol
0820: 64 20 74 68 61 74 20 5c 66 42 63 6c 6f 63 6b 20 d that \fBclock
0830: 6d 69 6c 6c 69 73 65 63 6f 6e 64 73 5c 66 52 20 milliseconds\fR
0840: 64 69 76 69 64 65 64 20 62 79 0a 2b 31 30 30 30 divided by.+1000
0850: 20 61 6e 64 20 5c 66 42 63 6c 6f 63 6b 20 6d 69 and \fBclock mi
0860: 63 72 6f 73 65 63 6f 6e 64 73 5c 66 52 20 64 69 croseconds\fR di
0870: 76 69 64 65 64 20 62 79 20 6f 6e 65 20 6d 69 6c vided by one mil
0880: 6c 69 6f 6e 20 69 73 20 74 68 65 20 73 61 6d 65 lion is the same
0890: 0a 2b 61 73 20 5c 66 42 63 6c 6f 63 6b 20 73 65 .+as \fBclock se
08a0: 63 6f 6e 64 73 5c 66 52 2e 0a 2b 0a 2b 4f 6e 20 conds\fR..+.+On
08b0: 73 6f 6d 65 20 68 61 72 64 77 61 72 65 2c 20 74 some hardware, t
08c0: 68 65 20 63 6f 75 6e 74 73 20 6f 66 20 6d 69 6c he counts of mil
08d0: 6c 69 73 65 63 6f 6e 64 73 20 61 6e 64 20 6d 69 liseconds and mi
08e0: 63 72 6f 73 65 63 6f 6e 64 73 20 6d 61 79 0a 2b croseconds may.+
08f0: 64 69 76 65 72 67 65 20 66 72 6f 6d 20 74 68 65 diverge from the
0900: 20 73 79 73 74 65 6d 20 63 6c 6f 63 6b 20 66 6f system clock fo
0910: 72 20 73 68 6f 72 74 20 70 65 72 69 6f 64 73 3b r short periods;
0920: 20 74 68 65 20 72 65 61 73 6f 6e 20 69 73 20 74 the reason is t
0930: 68 61 74 0a 2b 74 68 65 79 20 63 61 6e 20 62 65 hat.+they can be
0940: 20 64 65 72 69 76 65 64 20 66 72 6f 6d 20 64 69 derived from di
0950: 66 66 65 72 65 6e 74 20 73 6f 75 72 63 65 73 2c fferent sources,
0960: 20 61 6e 64 20 61 20 63 6f 6d 70 6c 65 78 20 70 and a complex p
0970: 72 6f 63 65 64 75 72 65 20 69 73 0a 2b 72 65 71 rocedure is.+req
0980: 75 69 72 65 64 20 74 6f 20 63 61 6c 69 62 72 61 uired to calibra
0990: 74 65 20 74 68 65 6d 2e 20 20 4d 6f 72 65 6f 76 te them. Moreov
09a0: 65 72 2c 20 54 63 6c 20 6d 61 6b 65 73 20 61 6e er, Tcl makes an
09b0: 20 65 66 66 6f 72 74 20 6e 65 76 65 72 20 74 6f effort never to
09c0: 0a 2b 68 61 76 65 20 74 68 65 20 63 6c 6f 63 6b .+have the clock
09d0: 20 6c 65 61 70 20 66 6f 72 77 61 72 64 20 6e 6f leap forward no
09e0: 72 20 61 70 70 65 61 72 20 74 6f 20 72 75 6e 20 r appear to run
09f0: 62 61 63 6b 77 61 72 64 2c 20 70 72 65 66 65 72 backward, prefer
0a00: 72 69 6e 67 0a 2b 69 6e 73 74 65 61 64 20 74 6f ring.+instead to
0a10: 20 73 6c 6f 77 20 6f 72 20 73 70 65 65 64 20 75 slow or speed u
0a20: 70 20 74 68 65 20 63 6c 6f 63 6b 20 66 72 65 71 p the clock freq
0a30: 75 65 6e 63 79 20 73 6c 69 67 68 74 6c 79 20 75 uency slightly u
0a40: 6e 74 69 6c 20 69 74 27 73 0a 2b 62 61 63 6b 20 ntil it's.+back
0a50: 69 6e 20 73 79 6e 63 68 72 6f 6e 69 7a 61 74 69 in synchronizati
0a60: 6f 6e 2e 20 20 46 6f 72 20 74 68 69 73 20 72 65 on. For this re
0a70: 61 73 6f 6e 2c 20 6d 6f 73 74 20 54 63 6c 20 70 ason, most Tcl p
0a80: 72 6f 67 72 61 6d 6d 65 72 73 20 6e 65 65 64 0a rogrammers need.
0a90: 2b 6e 65 76 65 72 20 77 6f 72 72 79 20 61 62 6f +never worry abo
0aa0: 75 74 20 73 75 63 68 20 70 68 65 6e 6f 6d 65 6e ut such phenomen
0ab0: 61 20 61 73 20 6c 65 61 70 20 73 65 63 6f 6e 64 a as leap second
0ac0: 73 2e 0a 2b 2e 56 45 20 38 2e 35 0a 2b 2e 54 50 s..+.VE 8.5.+.TP
0ad0: 0a 20 2e 53 48 20 45 58 41 4d 50 4c 45 0a 20 50 . .SH EXAMPLE. P
0ae0: 72 69 6e 74 20 6f 75 74 20 74 68 65 20 63 75 72 rint out the cur
0af0: 72 65 6e 74 20 64 61 74 65 20 61 6e 64 20 74 69 rent date and ti
0b00: 6d 65 2c 20 66 69 72 73 74 20 75 73 69 6e 67 20 me, first using
0b10: 74 68 65 20 64 65 66 61 75 6c 74 20 66 6f 72 6d the default form
0b20: 61 74 0a 20 61 6e 64 20 74 68 65 6e 20 75 73 69 at. and then usi
0b30: 6e 67 20 61 6e 20 49 53 4f 20 38 36 30 31 20 66 ng an ISO 8601 f
0b40: 6f 72 6d 61 74 3a 0a 49 6e 64 65 78 3a 20 67 65 ormat:.Index: ge
0b50: 6e 65 72 69 63 2f 74 63 6c 43 6c 6f 63 6b 2e 63 neric/tclClock.c
0b60: 0a 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d .===============
0b70: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
0b80: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
0b90: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
0ba0: 3d 3d 3d 3d 0a 52 43 53 20 66 69 6c 65 3a 20 2f ====.RCS file: /
0bb0: 63 76 73 72 6f 6f 74 2f 74 63 6c 2f 74 63 6c 2f cvsroot/tcl/tcl/
0bc0: 67 65 6e 65 72 69 63 2f 74 63 6c 43 6c 6f 63 6b generic/tclClock
0bd0: 2e 63 2c 76 0a 72 65 74 72 69 65 76 69 6e 67 20 .c,v.retrieving
0be0: 72 65 76 69 73 69 6f 6e 20 31 2e 32 38 0a 64 69 revision 1.28.di
0bf0: 66 66 20 2d 75 20 2d 72 31 2e 32 38 20 74 63 6c ff -u -r1.28 tcl
0c00: 43 6c 6f 63 6b 2e 63 0a 2d 2d 2d 20 67 65 6e 65 Clock.c.--- gene
0c10: 72 69 63 2f 74 63 6c 43 6c 6f 63 6b 2e 63 09 31 ric/tclClock.c.1
0c20: 34 20 4d 61 79 20 32 30 30 34 20 32 31 3a 34 33 4 May 2004 21:43
0c30: 3a 32 38 20 2d 30 30 30 30 09 31 2e 32 38 0a 2b :28 -0000.1.28.+
0c40: 2b 2b 20 67 65 6e 65 72 69 63 2f 74 63 6c 43 6c ++ generic/tclCl
0c50: 6f 63 6b 2e 63 09 31 35 20 4a 75 6c 20 32 30 30 ock.c.15 Jul 200
0c60: 34 20 31 37 3a 30 36 3a 30 38 20 2d 30 30 30 30 4 17:06:08 -0000
0c70: 0a 40 40 20 2d 36 38 2c 31 30 20 2b 36 38 2c 31 .@@ -68,10 +68,1
0c80: 32 20 40 40 0a 20 20 20 20 20 54 63 6c 5f 54 69 2 @@. Tcl_Ti
0c90: 6d 65 20 6e 6f 77 3b 09 09 2f 2a 20 43 75 72 72 me now;../* Curr
0ca0: 65 6e 74 20 74 69 6d 65 20 2a 2f 0a 20 0a 20 20 ent time */. .
0cb0: 20 20 20 73 74 61 74 69 63 20 43 4f 4e 53 54 20 static CONST
0cc0: 63 68 61 72 20 2a 73 77 69 74 63 68 65 73 5b 5d char *switches[]
0cd0: 20 3d 20 7b 0a 2d 09 22 63 6c 69 63 6b 73 22 2c = {.-."clicks",
0ce0: 20 22 66 6f 72 6d 61 74 22 2c 20 22 73 63 61 6e "format", "scan
0cf0: 22 2c 20 22 73 65 63 6f 6e 64 73 22 2c 20 28 63 ", "seconds", (c
0d00: 68 61 72 20 2a 29 20 4e 55 4c 4c 0a 2b 09 22 63 har *) NULL.+."c
0d10: 6c 69 63 6b 73 22 2c 20 22 66 6f 72 6d 61 74 22 licks", "format"
0d20: 2c 20 22 6d 69 63 72 6f 73 65 63 6f 6e 64 73 22 , "microseconds"
0d30: 2c 20 22 6d 69 6c 6c 69 73 65 63 6f 6e 64 73 22 , "milliseconds"
0d40: 2c 0a 2b 09 22 73 63 61 6e 22 2c 20 22 73 65 63 ,.+."scan", "sec
0d50: 6f 6e 64 73 22 2c 20 28 63 68 61 72 20 2a 29 20 onds", (char *)
0d60: 4e 55 4c 4c 0a 20 20 20 20 20 7d 3b 0a 20 20 20 NULL. };.
0d70: 20 20 65 6e 75 6d 20 63 6f 6d 6d 61 6e 64 20 7b enum command {
0d80: 0a 2d 09 43 4f 4d 4d 41 4e 44 5f 43 4c 49 43 4b .-.COMMAND_CLICK
0d90: 53 2c 20 43 4f 4d 4d 41 4e 44 5f 46 4f 52 4d 41 S, COMMAND_FORMA
0da0: 54 2c 20 43 4f 4d 4d 41 4e 44 5f 53 43 41 4e 2c T, COMMAND_SCAN,
0db0: 20 43 4f 4d 4d 41 4e 44 5f 53 45 43 4f 4e 44 53 COMMAND_SECONDS
0dc0: 0a 2b 09 43 4f 4d 4d 41 4e 44 5f 43 4c 49 43 4b .+.COMMAND_CLICK
0dd0: 53 2c 20 43 4f 4d 4d 41 4e 44 5f 46 4f 52 4d 41 S, COMMAND_FORMA
0de0: 54 2c 20 43 4f 4d 4d 41 4e 44 5f 4d 49 43 52 4f T, COMMAND_MICRO
0df0: 53 45 43 4f 4e 44 53 2c 0a 2b 09 43 4f 4d 4d 41 SECONDS,.+.COMMA
0e00: 4e 44 5f 4d 49 4c 4c 49 53 45 43 4f 4e 44 53 2c ND_MILLISECONDS,
0e10: 20 43 4f 4d 4d 41 4e 44 5f 53 43 41 4e 2c 20 43 COMMAND_SCAN, C
0e20: 4f 4d 4d 41 4e 44 5f 53 45 43 4f 4e 44 53 0a 20 OMMAND_SECONDS.
0e30: 20 20 20 20 7d 3b 0a 20 20 20 20 20 73 74 61 74 };. stat
0e40: 69 63 20 43 4f 4e 53 54 20 63 68 61 72 20 2a 63 ic CONST char *c
0e50: 6c 69 63 6b 73 53 77 69 74 63 68 65 73 5b 5d 20 licksSwitches[]
0e60: 3d 20 7b 0a 20 09 22 2d 6d 69 6c 6c 69 73 65 63 = {. ."-millisec
0e70: 6f 6e 64 73 22 2c 20 22 2d 6d 69 63 72 6f 73 65 onds", "-microse
0e80: 63 6f 6e 64 73 22 2c 20 28 63 68 61 72 2a 29 20 conds", (char*)
0e90: 4e 55 4c 4c 0a 40 40 20 2d 31 32 33 2c 36 20 2b NULL.@@ -123,6 +
0ea0: 31 32 35 2c 32 36 20 40 40 0a 20 09 20 20 20 20 125,26 @@. .
0eb0: 72 65 74 75 72 6e 20 54 43 4c 5f 4f 4b 3b 0a 20 return TCL_OK;.
0ec0: 09 7d 0a 20 0a 2b 09 63 61 73 65 20 43 4f 4d 4d .}. .+.case COMM
0ed0: 41 4e 44 5f 4d 49 43 52 4f 53 45 43 4f 4e 44 53 AND_MICROSECONDS
0ee0: 3a 20 2f 2a 20 6d 69 63 72 6f 73 65 63 6f 6e 64 : /* microsecond
0ef0: 73 20 2a 2f 0a 2b 09 20 20 20 20 69 66 20 28 6f s */.+. if (o
0f00: 62 6a 63 20 21 3d 20 32 29 20 7b 0a 2b 09 09 54 bjc != 2) {.+..T
0f10: 63 6c 5f 57 72 6f 6e 67 4e 75 6d 41 72 67 73 28 cl_WrongNumArgs(
0f20: 69 6e 74 65 72 70 2c 20 32 2c 20 6f 62 6a 76 2c interp, 2, objv,
0f30: 20 4e 55 4c 4c 29 3b 0a 2b 09 09 72 65 74 75 72 NULL);.+..retur
0f40: 6e 20 54 43 4c 5f 45 52 52 4f 52 3b 0a 2b 09 20 n TCL_ERROR;.+.
0f50: 20 20 20 7d 0a 2b 09 20 20 20 20 54 63 6c 5f 47 }.+. Tcl_G
0f60: 65 74 54 69 6d 65 28 26 6e 6f 77 29 3b 0a 2b 09 etTime(&now);.+.
0f70: 20 20 20 20 54 63 6c 5f 53 65 74 57 69 64 65 49 Tcl_SetWideI
0f80: 6e 74 4f 62 6a 28 72 65 73 75 6c 74 50 74 72 2c ntObj(resultPtr,
0f90: 0a 2b 09 09 09 20 20 20 20 20 20 28 28 54 63 6c .+... ((Tcl
0fa0: 5f 57 69 64 65 49 6e 74 29 20 6e 6f 77 2e 73 65 _WideInt) now.se
0fb0: 63 20 2a 20 31 30 30 30 30 30 30 20 2b 20 6e 6f c * 1000000 + no
0fc0: 77 2e 75 73 65 63 29 29 3b 0a 2b 09 20 20 20 20 w.usec));.+.
0fd0: 72 65 74 75 72 6e 20 54 43 4c 5f 4f 4b 3b 0a 2b return TCL_OK;.+
0fe0: 0a 2b 09 63 61 73 65 20 43 4f 4d 4d 41 4e 44 5f .+.case COMMAND_
0ff0: 4d 49 4c 4c 49 53 45 43 4f 4e 44 53 3a 20 2f 2a MILLISECONDS: /*
1000: 20 6d 69 6c 6c 69 73 65 63 6f 6e 64 73 20 2a 2f milliseconds */
1010: 0a 2b 09 20 20 20 20 69 66 20 28 6f 62 6a 63 20 .+. if (objc
1020: 21 3d 20 32 29 20 7b 0a 2b 09 09 54 63 6c 5f 57 != 2) {.+..Tcl_W
1030: 72 6f 6e 67 4e 75 6d 41 72 67 73 28 69 6e 74 65 rongNumArgs(inte
1040: 72 70 2c 20 32 2c 20 6f 62 6a 76 2c 20 4e 55 4c rp, 2, objv, NUL
1050: 4c 29 3b 0a 2b 09 09 72 65 74 75 72 6e 20 54 43 L);.+..return TC
1060: 4c 5f 45 52 52 4f 52 3b 0a 2b 09 20 20 20 20 7d L_ERROR;.+. }
1070: 0a 2b 09 20 20 20 20 54 63 6c 5f 47 65 74 54 69 .+. Tcl_GetTi
1080: 6d 65 28 26 6e 6f 77 29 3b 0a 2b 09 20 20 20 20 me(&now);.+.
1090: 54 63 6c 5f 53 65 74 57 69 64 65 49 6e 74 4f 62 Tcl_SetWideIntOb
10a0: 6a 28 72 65 73 75 6c 74 50 74 72 2c 0a 2b 09 09 j(resultPtr,.+..
10b0: 09 20 20 20 20 20 20 28 28 54 63 6c 5f 57 69 64 . ((Tcl_Wid
10c0: 65 49 6e 74 29 20 6e 6f 77 2e 73 65 63 20 2a 20 eInt) now.sec *
10d0: 31 30 30 30 20 2b 20 6e 6f 77 2e 75 73 65 63 20 1000 + now.usec
10e0: 2f 20 31 30 30 30 29 29 3b 0a 2b 09 20 20 20 20 / 1000));.+.
10f0: 72 65 74 75 72 6e 20 54 43 4c 5f 4f 4b 3b 0a 2b return TCL_OK;.+
1100: 0a 20 09 63 61 73 65 20 43 4f 4d 4d 41 4e 44 5f . .case COMMAND_
1110: 46 4f 52 4d 41 54 3a 09 09 09 2f 2a 20 66 6f 72 FORMAT:.../* for
1120: 6d 61 74 20 2a 2f 0a 20 09 20 20 20 20 69 66 20 mat */. . if
1130: 28 28 6f 62 6a 63 20 3c 20 33 29 20 7c 7c 20 28 ((objc < 3) || (
1140: 6f 62 6a 63 20 3e 20 37 29 29 20 7b 0a 20 09 09 objc > 7)) {. ..
1150: 77 72 6f 6e 67 46 6d 74 41 72 67 73 3a 0a 49 6e wrongFmtArgs:.In
1160: 64 65 78 3a 20 74 65 73 74 73 2f 63 6c 6f 63 6b dex: tests/clock
1170: 2e 74 65 73 74 0a 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d .test.==========
1180: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
1190: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
11a0: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
11b0: 3d 3d 3d 3d 3d 3d 3d 3d 3d 0a 52 43 53 20 66 69 =========.RCS fi
11c0: 6c 65 3a 20 2f 63 76 73 72 6f 6f 74 2f 74 63 6c le: /cvsroot/tcl
11d0: 2f 74 63 6c 2f 74 65 73 74 73 2f 63 6c 6f 63 6b /tcl/tests/clock
11e0: 2e 74 65 73 74 2c 76 0a 72 65 74 72 69 65 76 69 .test,v.retrievi
11f0: 6e 67 20 72 65 76 69 73 69 6f 6e 20 31 2e 33 34 ng revision 1.34
1200: 0a 64 69 66 66 20 2d 75 20 2d 72 31 2e 33 34 20 .diff -u -r1.34
1210: 63 6c 6f 63 6b 2e 74 65 73 74 0a 2d 2d 2d 20 74 clock.test.--- t
1220: 65 73 74 73 2f 63 6c 6f 63 6b 2e 74 65 73 74 09 ests/clock.test.
1230: 31 30 20 4a 75 6c 20 32 30 30 34 20 32 31 3a 32 10 Jul 2004 21:2
1240: 36 3a 31 30 20 2d 30 30 30 30 09 31 2e 33 34 0a 6:10 -0000.1.34.
1250: 2b 2b 2b 20 74 65 73 74 73 2f 63 6c 6f 63 6b 2e +++ tests/clock.
1260: 74 65 73 74 09 31 35 20 4a 75 6c 20 32 30 30 34 test.15 Jul 2004
1270: 20 31 37 3a 30 36 3a 30 39 20 2d 30 30 30 30 0a 17:06:09 -0000.
1280: 40 40 20 2d 34 31 2c 37 20 2b 34 31 2c 37 20 40 @@ -41,7 +41,7 @
1290: 40 0a 20 7d 20 7b 31 20 7b 77 72 6f 6e 67 20 23 @. } {1 {wrong #
12a0: 20 61 72 67 73 3a 20 73 68 6f 75 6c 64 20 62 65 args: should be
12b0: 20 22 63 6c 6f 63 6b 20 6f 70 74 69 6f 6e 20 3f "clock option ?
12c0: 61 72 67 20 2e 2e 2e 3f 22 7d 7d 0a 20 74 65 73 arg ...?"}}. tes
12d0: 74 20 63 6c 6f 63 6b 2d 31 2e 32 20 7b 63 6c 6f t clock-1.2 {clo
12e0: 63 6b 20 74 65 73 74 73 7d 20 7b 0a 20 20 20 20 ck tests} {.
12f0: 20 6c 69 73 74 20 5b 63 61 74 63 68 20 7b 63 6c list [catch {cl
1300: 6f 63 6b 20 66 6f 6f 7d 20 6d 73 67 5d 20 24 6d ock foo} msg] $m
1310: 73 67 0a 2d 7d 20 7b 31 20 7b 62 61 64 20 6f 70 sg.-} {1 {bad op
1320: 74 69 6f 6e 20 22 66 6f 6f 22 3a 20 6d 75 73 74 tion "foo": must
1330: 20 62 65 20 63 6c 69 63 6b 73 2c 20 66 6f 72 6d be clicks, form
1340: 61 74 2c 20 73 63 61 6e 2c 20 6f 72 20 73 65 63 at, scan, or sec
1350: 6f 6e 64 73 7d 7d 0a 2b 7d 20 7b 31 20 7b 62 61 onds}}.+} {1 {ba
1360: 64 20 6f 70 74 69 6f 6e 20 22 66 6f 6f 22 3a 20 d option "foo":
1370: 6d 75 73 74 20 62 65 20 63 6c 69 63 6b 73 2c 20 must be clicks,
1380: 66 6f 72 6d 61 74 2c 20 6d 69 63 72 6f 73 65 63 format, microsec
1390: 6f 6e 64 73 2c 20 6d 69 6c 6c 69 73 65 63 6f 6e onds, millisecon
13a0: 64 73 2c 20 73 63 61 6e 2c 20 6f 72 20 73 65 63 ds, scan, or sec
13b0: 6f 6e 64 73 7d 7d 0a 20 0a 20 23 20 63 6c 6f 63 onds}}. . # cloc
13c0: 6b 20 63 6c 69 63 6b 73 0a 20 74 65 73 74 20 63 k clicks. test c
13d0: 6c 6f 63 6b 2d 32 2e 31 20 7b 63 6c 6f 63 6b 20 lock-2.1 {clock
13e0: 63 6c 69 63 6b 73 20 74 65 73 74 73 7d 20 7b 0a clicks tests} {.
13f0: 40 40 20 2d 37 30 39 2c 36 20 2b 37 30 39 2c 38 @@ -709,6 +709,8
1400: 30 20 40 40 0a 20 20 20 20 20 63 6c 6f 63 6b 20 0 @@. clock
1410: 73 63 61 6e 20 22 31 36 30 30 22 20 2d 67 6d 74 scan "1600" -gmt
1420: 20 74 72 75 65 20 2d 62 61 73 65 20 24 62 61 73 true -base $bas
1430: 65 0a 20 7d 20 31 30 37 38 38 34 38 30 30 30 0a e. } 1078848000.
1440: 20 0a 2b 23 23 23 23 23 23 23 23 23 23 23 23 23 .+#############
1450: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 ################
1460: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 ################
1470: 23 23 0a 2b 23 20 5b 63 6c 6f 63 6b 20 6d 69 6c ##.+# [clock mil
1480: 6c 69 73 65 63 6f 6e 64 73 5d 20 61 6e 64 20 5b liseconds] and [
1490: 63 6c 6f 63 6b 20 6d 69 63 72 6f 73 65 63 6f 6e clock microsecon
14a0: 64 73 5d 0a 2b 0a 2b 74 65 73 74 20 63 6c 6f 63 ds].+.+test cloc
14b0: 6b 2d 31 32 2e 31 20 7b 6d 69 6c 6c 69 73 65 63 k-12.1 {millisec
14c0: 6f 6e 64 73 20 77 69 74 68 20 65 78 63 65 73 73 onds with excess
14d0: 20 61 72 67 75 6d 65 6e 74 7d 20 7b 0a 2b 20 20 argument} {.+
14e0: 20 20 6c 69 73 74 20 5b 63 61 74 63 68 20 7b 63 list [catch {c
14f0: 6c 6f 63 6b 20 6d 69 6c 6c 69 73 65 63 6f 6e 64 lock millisecond
1500: 73 20 66 6f 6f 7d 20 65 72 72 6f 72 5d 20 24 65 s foo} error] $e
1510: 72 72 6f 72 0a 2b 7d 20 7b 31 20 7b 77 72 6f 6e rror.+} {1 {wron
1520: 67 20 23 20 61 72 67 73 3a 20 73 68 6f 75 6c 64 g # args: should
1530: 20 62 65 20 22 63 6c 6f 63 6b 20 6d 69 6c 6c 69 be "clock milli
1540: 73 65 63 6f 6e 64 73 22 7d 7d 0a 2b 0a 2b 74 65 seconds"}}.+.+te
1550: 73 74 20 63 6c 6f 63 6b 2d 31 32 2e 32 20 7b 63 st clock-12.2 {c
1560: 6c 6f 63 6b 20 6d 69 6c 6c 69 73 65 63 6f 6e 64 lock millisecond
1570: 73 20 74 69 6d 69 6e 67 20 74 65 73 74 7d 20 7b s timing test} {
1580: 0a 2b 20 20 20 20 73 65 74 20 73 74 61 72 74 20 .+ set start
1590: 5b 63 6c 6f 63 6b 20 6d 69 6c 6c 69 5d 0a 2b 20 [clock milli].+
15a0: 20 20 20 61 66 74 65 72 20 31 30 0a 2b 20 20 20 after 10.+
15b0: 20 73 65 74 20 65 6e 64 20 5b 63 6c 6f 63 6b 20 set end [clock
15c0: 6d 69 6c 6c 69 5d 0a 2b 20 20 20 20 23 20 36 30 milli].+ # 60
15d0: 20 6d 73 65 63 73 20 73 65 65 6d 73 20 74 6f 20 msecs seems to
15e0: 62 65 20 74 68 65 20 6d 61 78 20 74 69 6d 65 20 be the max time
15f0: 73 6c 69 63 65 20 75 6e 64 65 72 20 57 69 6e 64 slice under Wind
1600: 6f 77 73 20 39 35 2f 39 38 0a 2b 20 20 20 20 65 ows 95/98.+ e
1610: 78 70 72 20 7b 28 24 65 6e 64 20 3e 20 24 73 74 xpr {($end > $st
1620: 61 72 74 29 20 26 26 20 28 28 24 65 6e 64 20 2d art) && (($end -
1630: 20 24 73 74 61 72 74 29 20 3c 3d 20 36 30 29 7d $start) <= 60)}
1640: 0a 2b 7d 20 7b 31 7d 0a 2b 0a 2b 74 65 73 74 20 .+} {1}.+.+test
1650: 63 6c 6f 63 6b 2d 31 32 2e 33 20 7b 63 6c 6f 63 clock-12.3 {cloc
1660: 6b 20 6d 69 63 72 6f 73 65 63 6f 6e 64 73 20 74 k microseconds t
1670: 69 6d 69 6e 67 20 74 65 73 74 7d 20 7b 0a 2b 20 iming test} {.+
1680: 20 20 20 73 65 74 20 73 74 61 72 74 20 5b 63 6c set start [cl
1690: 6f 63 6b 20 6d 69 63 72 6f 5d 0a 2b 20 20 20 20 ock micro].+
16a0: 61 66 74 65 72 20 31 30 0a 2b 20 20 20 20 73 65 after 10.+ se
16b0: 74 20 65 6e 64 20 5b 63 6c 6f 63 6b 20 6d 69 63 t end [clock mic
16c0: 72 6f 5d 0a 2b 20 20 20 20 23 20 36 30 20 6d 73 ro].+ # 60 ms
16d0: 65 63 73 20 73 65 65 6d 73 20 74 6f 20 62 65 20 ecs seems to be
16e0: 74 68 65 20 6d 61 78 20 74 69 6d 65 20 73 6c 69 the max time sli
16f0: 63 65 20 75 6e 64 65 72 20 57 69 6e 64 6f 77 73 ce under Windows
1700: 20 39 35 2f 39 38 0a 2b 20 20 20 20 65 78 70 72 95/98.+ expr
1710: 20 7b 28 24 65 6e 64 20 3e 20 24 73 74 61 72 74 {($end > $start
1720: 29 20 26 26 20 28 28 24 65 6e 64 20 2d 20 24 73 ) && (($end - $s
1730: 74 61 72 74 29 20 3c 3d 20 36 30 30 30 30 29 7d tart) <= 60000)}
1740: 0a 2b 7d 20 7b 31 7d 0a 2b 0a 2b 74 65 73 74 20 .+} {1}.+.+test
1750: 63 6c 6f 63 6b 2d 31 32 2e 33 20 7b 63 6c 6f 63 clock-12.3 {cloc
1760: 6b 20 63 6c 69 63 6b 73 20 74 65 73 74 2c 20 6d k clicks test, m
1770: 69 6c 6c 69 73 20 61 6c 69 67 6e 20 77 69 74 68 illis align with
1780: 20 73 65 63 6f 6e 64 73 7d 20 7b 0a 2b 20 20 20 seconds} {.+
1790: 20 73 65 74 20 74 31 20 5b 63 6c 6f 63 6b 20 73 set t1 [clock s
17a0: 65 63 6f 6e 64 73 5d 0a 2b 20 20 20 20 77 68 69 econds].+ whi
17b0: 6c 65 20 7b 20 31 20 7d 20 7b 0a 2b 09 73 65 74 le { 1 } {.+.set
17c0: 20 74 32 20 5b 63 6c 6f 63 6b 20 63 6c 69 63 6b t2 [clock click
17d0: 73 20 2d 6d 69 6c 6c 69 73 5d 0a 2b 09 73 65 74 s -millis].+.set
17e0: 20 74 33 20 5b 63 6c 6f 63 6b 20 73 65 63 6f 6e t3 [clock secon
17f0: 64 73 5d 0a 2b 09 69 66 20 7b 20 24 74 33 20 3d ds].+.if { $t3 =
1800: 3d 20 24 74 31 20 7d 20 62 72 65 61 6b 0a 2b 09 = $t1 } break.+.
1810: 73 65 74 20 74 31 20 24 74 33 0a 2b 20 20 20 20 set t1 $t3.+
1820: 7d 0a 2b 20 20 20 20 65 78 70 72 20 7b 20 24 74 }.+ expr { $t
1830: 32 20 2f 20 31 30 30 30 20 3d 3d 20 24 74 33 20 2 / 1000 == $t3
1840: 7d 0a 2b 7d 20 7b 31 7d 0a 2b 0a 2b 74 65 73 74 }.+} {1}.+.+test
1850: 20 63 6c 6f 63 6b 2d 31 32 2e 34 20 7b 63 6c 6f clock-12.4 {clo
1860: 63 6b 20 6d 69 63 72 6f 73 20 61 6c 69 67 6e 20 ck micros align
1870: 77 69 74 68 20 73 65 63 6f 6e 64 73 7d 20 7b 0a with seconds} {.
1880: 2b 20 20 20 20 73 65 74 20 74 31 20 5b 63 6c 6f + set t1 [clo
1890: 63 6b 20 73 65 63 6f 6e 64 73 5d 0a 2b 20 20 20 ck seconds].+
18a0: 20 77 68 69 6c 65 20 7b 20 31 20 7d 20 7b 0a 2b while { 1 } {.+
18b0: 09 73 65 74 20 74 32 20 5b 63 6c 6f 63 6b 20 6d .set t2 [clock m
18c0: 69 63 72 6f 73 5d 0a 2b 09 73 65 74 20 74 33 20 icros].+.set t3
18d0: 5b 63 6c 6f 63 6b 20 73 65 63 6f 6e 64 73 5d 0a [clock seconds].
18e0: 2b 09 69 66 20 7b 20 24 74 33 20 3d 3d 20 24 74 +.if { $t3 == $t
18f0: 31 20 7d 20 62 72 65 61 6b 0a 2b 09 73 65 74 20 1 } break.+.set
1900: 74 31 20 24 74 33 0a 2b 20 20 20 20 7d 0a 2b 20 t1 $t3.+ }.+
1910: 20 20 20 65 78 70 72 20 7b 20 24 74 32 20 2f 20 expr { $t2 /
1920: 31 30 30 30 30 30 30 20 3d 3d 20 24 74 33 20 7d 1000000 == $t3 }
1930: 0a 2b 7d 20 7b 31 7d 0a 2b 0a 2b 74 65 73 74 20 .+} {1}.+.+test
1940: 63 6c 6f 63 6b 2d 31 32 2e 35 20 7b 63 6c 6f 63 clock-12.5 {cloc
1950: 6b 20 6d 69 6c 6c 69 73 20 61 6c 69 67 6e 20 77 k millis align w
1960: 69 74 68 20 6d 69 63 72 6f 73 7d 20 7b 0a 2b 20 ith micros} {.+
1970: 20 20 20 73 65 74 20 74 31 20 5b 63 6c 6f 63 6b set t1 [clock
1980: 20 6d 69 6c 6c 69 73 5d 0a 2b 20 20 20 20 73 65 millis].+ se
1990: 74 20 69 20 30 0a 2b 20 20 20 20 77 68 69 6c 65 t i 0.+ while
19a0: 20 7b 20 24 69 20 3c 20 31 30 30 30 20 7d 20 7b { $i < 1000 } {
19b0: 0a 2b 09 73 65 74 20 74 32 20 5b 63 6c 6f 63 6b .+.set t2 [clock
19c0: 20 6d 69 63 72 6f 73 5d 0a 2b 09 73 65 74 20 74 micros].+.set t
19d0: 33 20 5b 63 6c 6f 63 6b 20 6d 69 6c 6c 69 73 5d 3 [clock millis]
19e0: 0a 2b 09 69 66 20 7b 20 24 74 33 20 3d 3d 20 24 .+.if { $t3 == $
19f0: 74 31 20 7d 20 62 72 65 61 6b 0a 2b 09 73 65 74 t1 } break.+.set
1a00: 20 74 31 20 24 74 33 0a 2b 20 20 20 20 20 20 20 t1 $t3.+
1a10: 20 69 6e 63 72 20 69 0a 2b 20 20 20 20 7d 0a 2b incr i.+ }.+
1a20: 20 20 20 20 69 66 20 7b 20 24 69 20 3e 3d 20 31 if { $i >= 1
1a30: 30 30 30 20 7d 20 7b 0a 2b 20 20 20 20 20 20 20 000 } {.+
1a40: 20 73 65 74 20 72 65 73 75 6c 74 20 7b 63 61 6e set result {can
1a50: 27 74 20 74 65 73 74 20 6d 69 6c 6c 69 73 2f 6d 't test millis/m
1a60: 69 63 72 6f 73 20 61 6c 69 67 6e 6d 65 6e 74 2c icros alignment,
1a70: 20 6c 6f 6f 70 20 72 75 6e 6e 69 6e 67 20 74 6f loop running to
1a80: 6f 20 73 6c 6f 77 7d 0a 2b 20 20 20 20 7d 20 65 o slow}.+ } e
1a90: 6c 73 65 20 7b 0a 2b 20 20 20 20 20 20 20 20 73 lse {.+ s
1aa0: 65 74 20 72 65 73 75 6c 74 20 5b 65 78 70 72 20 et result [expr
1ab0: 7b 20 24 74 32 20 2f 20 31 30 30 30 20 3d 3d 20 { $t2 / 1000 ==
1ac0: 24 74 33 20 7d 5d 0a 2b 20 20 20 20 7d 0a 2b 20 $t3 }].+ }.+
1ad0: 20 20 20 73 65 74 20 72 65 73 75 6c 74 0a 2b 7d set result.+}
1ae0: 20 7b 31 7d 0a 2b 0a 2b 74 65 73 74 20 63 6c 6f {1}.+.+test clo
1af0: 63 6b 2d 31 32 2e 36 20 7b 63 6c 6f 63 6b 20 6d ck-12.6 {clock m
1b00: 69 6c 6c 69 73 65 63 6f 6e 64 73 20 74 65 73 74 illiseconds test
1b10: 73 7d 20 7b 0a 2b 20 20 20 20 65 78 70 72 20 7b s} {.+ expr {
1b20: 5b 63 6c 6f 63 6b 20 6d 69 6c 6c 69 73 65 63 6f [clock milliseco
1b30: 6e 64 73 5d 2b 31 7d 0a 2b 20 20 20 20 63 6f 6e nds]+1}.+ con
1b40: 63 61 74 20 7b 7d 0a 2b 7d 20 7b 7d 0a 2b 0a 2b cat {}.+} {}.+.+
1b50: 74 65 73 74 20 63 6c 6f 63 6b 2d 31 32 2e 37 20 test clock-12.7
1b60: 7b 63 6c 6f 63 6b 20 6d 69 63 72 6f 73 65 63 6f {clock microseco
1b70: 6e 64 73 20 74 65 73 74 73 7d 20 7b 0a 2b 20 20 nds tests} {.+
1b80: 20 20 65 78 70 72 20 7b 5b 63 6c 6f 63 6b 20 6d expr {[clock m
1b90: 69 63 72 6f 73 65 63 6f 6e 64 73 5d 2b 31 7d 0a icroseconds]+1}.
1ba0: 2b 20 20 20 20 63 6f 6e 63 61 74 20 7b 7d 0a 2b + concat {}.+
1bb0: 7d 20 7b 7d 0a 2b 0a 2b 0a 20 69 66 20 7b 20 5b } {}.+.+. if { [
1bc0: 69 6e 66 6f 20 65 78 69 73 74 73 20 6f 6c 64 6c info exists oldl
1bd0: 63 74 69 6d 65 5d 20 7d 20 7b 0a 20 20 20 20 20 ctime] } {.
1be0: 73 65 74 20 65 6e 76 28 4c 43 5f 54 49 4d 45 29 set env(LC_TIME)
1bf0: 20 24 6f 6c 64 6c 63 74 69 6d 65 0a 20 7d 20 65 $oldlctime. } e
1c00: 6c 73 65 20 7b 0a lse {.