Animations and Timing issues

RJM A small timing jitter test program for exploring real-time resp. latency performance of systems:

#! /usr/bin/tclsh
if {$argc!=1} {
    puts "usage jitter <interval_ms>"
    return 0
}
package require Tk

proc timed_event {interval} {
    global count lastclock timediff_old
    set currentclock [clock microseconds]
    after $interval timed_event $interval
    incr count
    set timediff [expr {($currentclock - $lastclock)*0.01}]
    .c itemconfig value -text [expr {$timediff*0.1}]
    .c create line $count $timediff [expr {$count+1}] $timediff_old
    set lastclock $currentclock
    set timediff_old $timediff
}

set interval $argv
canvas .c -bg white -height 440 -width 630
.c create text 10 10 -text $interval
.c create text 50 10 -tag value -text ""
set tcl_precision 12
set timediff_old 0

bind .c <Configure> {
    set lastclock [clock microseconds]
    after $interval timed_event $interval
}
pack .c

This program has been used to check whether computer performance is sufficient for certain tcl/tk algorithms, e.g. after-based animations. Let's illustrate two test results:

Windows XP:

https://wiki.tcl-lang.org/_repo/images/jitter-winXP.png

The test program is called from the command line using the desired interval time in ms as an argument. This value is shown on the top left, while the actal value-per-interval is shown, too. The time advance is horizontal, while the vertical scale gives an impression of the interval time (to bottom is longer interval time). The peculiar vertical lines are due to bad latencies in Windows. Upon experiencing with different intervals it points out that the specific XP machine (a dual core machine) exhibits 15 ms timing resolution with the after command (e.g. after 20 yields approx. 30 ms intervals).

Hovering with the mouse over the window makes very worse result, contrary to Linux (on the same machine, see below):

https://wiki.tcl-lang.org/_repo/images/jitter_linux.png

In general, much less jitter is exhibited at all, and the intervals can be specified with a much better granularity.

The test program may prove a high usability when testing performance with embedded systems where the results of tweaking linux kernels can be observed using this test program (e.g. with target linux equipped with etcl from Evolane.

The program operates with creation of small line pieces instead of adding new coordinate pairs to one single line. This way on slower (embedded) machines it can be obeyed that the real interval time is going to increase steeply as the time and the drawing advances to the right - due to more computational work to do while creating the next line piece. The printing of interval values each interval also may have an impact on the curve, or intensity of jitter.