Skip to content
Tcl Source Code View Ticket
Login

View Ticket

New command "timerate": measurement of execution time

Closed / Acceptedda2cb25ca2e6d5e6a2703f377960ce8731ecffb6Created 10 years agoUpdated 8 years ago
Descriptionhtml2017-01-09 19:24:08

This is a interim PR, back-porting command timerate from my tclSE engine (previous PR on github).

See branch sebres-trunk-timerate.

Currently used as merge-point for clock-speed-up branch to compare performance between original tcl-clock and new tcl-clock engines.

Contains:

  • new command timerate, that allows to do the measurement of code executing more precise and in opposition to command time is time-related (not count-related);
  • small fix to test tcl-clock under Windows (registry in development env);

Additionally pros of command "timerate"

  • timerate can be calibrated to minimize influence of measurement overhead (and byte code execution overhead) - timerate -calibrate {}.
    Following example diff shows influence of measurement and execution overheads (the times retrieved for execution of empty scope-block resp. of each set i ... is more precise after calibration), e. g. in reality the execution time of set i ... amounts to ca. 0.057 µs/#:
+ % # calibrate to minimize influence of overhead:
+ % timerate -calibrate {}
+ 0.04763798110968011 µs/#-overhead, 0.048467 µs/#, 40275119 #, 20632745 #/sec
  % timerate {}
- 0.049425 µs/#, 20232613 #, 20232613 #/sec
+ 0.003276 µs/#, 19640807 #, 305208960 #/sec
  % timerate {set i 0} 5000
- 0.155394 µs/#, 32176202 #, 6435240 #/sec
+ 0.057090 µs/#, 47953979 #, 17516238 #/sec
  % timerate {set i 0; set i 1} 5000
- 0.221634 µs/#, 22559694 #, 4511938 #/sec
+ 0.113668 µs/#, 31042572 #, 8797543 #/sec
  % timerate {set i 0; set i 1; set i 2} 5000
- 0.293191 µs/#, 17053736 #, 3410747 #/sec
+ 0.190558 µs/#, 21012023 #, 5247746 #/sec
  • to reset previously calibrated overhead timerate -calibrate {} 0 can be used;
  • it can measure compiled and not compiled code pieces (use option -direct to disable "compilation" outside of measure cycle, and will be executed by TclEvalObjEx instead TclNRExecuteByteCode);
    Normally it uses compiled version to measure (as it would be a part of compiled script or procedure body):
- # measure not-compiled version:
- % timerate -direct {}
- 0.089162 µs/#, 11215515 #, 11215515 #/sec
+ # measure compiled version:
+ % timerate {}
+ 0.049425 µs/#, 20232613 #, 20232613 #/sec
  • with option -overhead an external calculated overhead can be specified for the timerate command to measure execution of the part of script. Following example shows possibility to ignore overhead of execution of _init procedure resp. more precise the speed of part string tolower ... only:
% proc _init {} { string trim " test " }
% timerate { set obj [_init]; string tolower $obj }
0.758217 µs/#, 1318883 #, 1318883 #/sec
% timerate \
   -overhead [lindex [timerate { set obj [_init] }] 0] \
           { set obj [_init]; string tolower $obj }
0.097757 µs/#, 1393420 #, 10229413 #/sec

sebreswiki2019-03-06 13:11:51

Integrated as part of TIP#527.

Log in (anonymous is fine) to add a comment.