07-22-2017, 00:28 +0200
AuthorPost
thommey  02-27-2007, 22:49   | [TCL] Synchronized high resolution timestamp Jabber
(Administrator)
Member since 03/2004
62 Posts
                                                                                                                              
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# This returns the current seconds of the timestamp
proc secs {} { clock format [clock seconds] -format %S }

# Because clock clicks are asynchronous, we need to check at what [clock clicks] seconds usually switch. So we do that here:
proc getsecswitch {} {
    set s [secs]
    while {$s == [secs]} { update }
    return [string range [clock clicks] end-5 end-3]
}

# That won't change while the interpreter is still running (CPU running)
set ::secswitch [getsecswitch]

proc getms {} {
    return [string range [expr {[clock clicks] - $::secswitch * 1000}] end-5 end-3]
}


# Example of usage:
proc timestamp {} {
    return "[clock format [clock seconds] -format %H:%M.%S]`[getms]"
}


# Verify that it's working
set s [secs]
while {$s == [secs]} { update }
if {[string range [getms] 0 1] != "00"} {
    #   "Warning! High precision clock doesn't work as it should!"
}
if {[string index [getms] end] != "0"} {
    #   "High precision clock works doesn't work with highest precision (<10ms difference)"
}
# "High precision clock set up and working perfectly."

This post was edited 2 times, last on 02-17-2008, 13:31 by thommey
Advanced options for this topic:

Ignore this topic (Do not list this topic in the "unread topics" search. You are currently not ignoring this topic.)
Hide this topic (Hidden topics are not displayed in the topics list. This topic is currently not hidden.)
Go to forum

Unclassified NewsBoard 1.5.3-d | © 2003-4 by Yves Goergen