Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tclSE-back-port: timerate and more #3

Open
wants to merge 12 commits into
base: trunk
Choose a base branch
from

Conversation

sebres
Copy link
Owner

@sebres sebres commented Jan 3, 2017

This is a interim PR back-porting some features from my tclSE engine.
Currently used as merge-point to #2 to compare performance between original tcl-clock and new tcl-clock engines.

Contains:

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

…out `-gmt 1`, because the return value would be -3600):

  % clock scan "01.01.1970" -locale current -format %x
  time value too large/small to represent
…" the execution limited by fixed time (in milliseconds) instead of repetition count (more precise results, to prevent very long execution time it is no more necessary to estimate repetition count)
… to 5000 now), because otherwise sporadically stutters on some platforms on very fast iterations (<= 1µs/#)
…ance counters actualized in calibration thread in UpdateTimeEachSecond;

This entails that sometimes sporadically time-drifts resp. jump-esque time-shifts occurred, what for example produces very confusing results during time measurement.
[unix] wrong cast fixed in TclpGetWideClicks: multiplication with 1000000 in long int may cause overflow
…00000; more precise threshold handling after NativeGetTime fix.
…verhead):

- use pre-compiled byte code and TclNRExecuteByteCode inside measure cycle;
- calibration possibility (through call of `timerate {}` to enter calibration cycle and obtain current overhead);

# Conflicts:
#	win/test-performance.tcl
… better precision `timerate {} 10000` could be used) + increase minimal threshold;
…ate? ?-overhead double? command ?time?;

limit default calibration cycle by precision of 0.01% (for exact precision an exact time could be given e. g. `timerate -calibrate {} 10000`);
… if object internal representation changed, example:

`set code { regexp {\w} $code }; timerate $code`

# Conflicts:
#	generic/tclCmdMZ.c
@sebres
Copy link
Owner Author

sebres commented Jan 4, 2017

Have a small amend for this trunk-based branch in d6d3cb9, that was forgotten, because would be not necessary in tclSE at all (the objects could own more as one slot with internal representation there, so byte-code will be not released, if e. g. unicode representation needed, so exists as long as the object exists).

Without this fix following code produces a segfault through removed byte-code representation in the meantime:

set code { regexp {\w} $code }
timerate $code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant