Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: f6ceaa5c4f68ab2ad27e870942b74c0ba7bd8bf6
Ticket: da2cb25ca2e6d5e6a2703f377960ce8731ecffb6
New command "timerate": measurement of execution time
User & Date: sebres on 2017-01-09 19:24:08
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/html"
  4. comment changed to:
    <p>This is a interim PR, back-porting command <b>timerate</b> from my tclSE engine (<a href="https://github.com/sebres/tcl/pull/3">previous PR on github</a>).<br>
    <br>
    See branch <a href="timeline?n=100&r=sebres-trunk-timerate">sebres-trunk-timerate</a>.<br><br>
    Currently used as merge-point for clock-speed-up branch to compare performance between original tcl-clock and new tcl-clock engines.</p>
    <h4>Contains:</h4>
    <ul>
    <li>new command <code>timerate</code>, that allows to do the measurement of code executing more precise and in opposition to command <code>time</code> is time-related (not count-related);</li>
    <li>small fix to test tcl-clock under Windows (registry in development env);</li>
    </ul>
    <h4>Additionally pros of command "timerate"</h4>
    <ul>
    <li><code>timerate</code> can be calibrated to minimize influence of measurement overhead (and byte code execution overhead) - <code>timerate -calibrate {}</code>. <br>Following example diff shows influence of measurement and execution overheads (the times retrieved for execution of empty scope-block resp. of each <code>set i ...</code> is more precise after calibration), e. g. in reality the execution time of <code>set i ...</code> amounts to ca. 0.057 µs/#:</li>
    </ul>
    <div class="highlight highlight-source-diff"><pre><span class="pl-mi1"><span class="pl-mi1">+</span> % # calibrate to minimize influence of overhead:</span>
    <span class="pl-mi1"><span class="pl-mi1">+</span> % timerate -calibrate {}</span>
    <span class="pl-mi1"><span class="pl-mi1">+</span> 0.04763798110968011 µs/#-overhead, 0.048467 µs/#, 40275119 #, 20632745 #/sec</span>
      % timerate {}
    <span class="pl-md"><span class="pl-md">-</span> 0.049425 µs/#, 20232613 #, 20232613 #/sec</span>
    <span class="pl-mi1"><span class="pl-mi1">+</span> 0.003276 µs/#, 19640807 #, 305208960 #/sec</span>
      % timerate {set i 0} 5000
    <span class="pl-md"><span class="pl-md">-</span> 0.155394 µs/#, 32176202 #, 6435240 #/sec</span>
    <span class="pl-mi1"><span class="pl-mi1">+</span> 0.057090 µs/#, 47953979 #, 17516238 #/sec</span>
      % timerate {set i 0; set i 1} 5000
    <span class="pl-md"><span class="pl-md">-</span> 0.221634 µs/#, 22559694 #, 4511938 #/sec</span>
    <span class="pl-mi1"><span class="pl-mi1">+</span> 0.113668 µs/#, 31042572 #, 8797543 #/sec</span>
      % timerate {set i 0; set i 1; set i 2} 5000
    <span class="pl-md"><span class="pl-md">-</span> 0.293191 µs/#, 17053736 #, 3410747 #/sec</span>
    <span class="pl-mi1"><span class="pl-mi1">+</span> 0.190558 µs/#, 21012023 #, 5247746 #/sec</span></pre></div>
    <ul>
    <li>to reset previously calibrated overhead <code>timerate -calibrate {} 0</code> can be used;</li>
    <li>it can measure compiled and not compiled code pieces (use option <code>-direct</code> to disable "compilation" outside of measure cycle, and will be executed by <code>TclEvalObjEx</code> instead <code>TclNRExecuteByteCode</code>);<br>
    Normally it uses compiled version to measure (as it would be a part of compiled script or procedure body):</li>
    </ul>
    <div class="highlight highlight-source-diff"><pre><span class="pl-md"><span class="pl-md">-</span> # measure not-compiled version:</span>
    <span class="pl-md"><span class="pl-md">-</span> % timerate -direct {}</span>
    <span class="pl-md"><span class="pl-md">-</span> 0.089162 µs/#, 11215515 #, 11215515 #/sec</span>
    <span class="pl-mi1"><span class="pl-mi1">+</span> # measure compiled version:</span>
    <span class="pl-mi1"><span class="pl-mi1">+</span> % timerate {}</span>
    <span class="pl-mi1"><span class="pl-mi1">+</span> 0.049425 µs/#, 20232613 #, 20232613 #/sec</span></pre></div>
    <ul>
    <li>with option <code>-overhead</code> an external calculated overhead can be specified for the <code>timerate</code> command to measure execution of the part of script. Following example shows possibility to ignore overhead of execution of <code>_init</code> procedure resp. more precise the speed of part <code>string tolower ...</code> only:</li>
    </ul>
    <pre><code>% 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
    </code></pre>
    
  5. foundin changed to: "tcl8.7 (portable to tcl8.6)"
  6. is_private changed to: "0"
  7. login: "sebres"
  8. priority changed to: "5 Medium"
  9. resolution changed to: "None"
  10. severity changed to: "Minor"
  11. status changed to: "Open"
  12. submitter changed to: "sebres"
  13. subsystem changed to: "- New Builtin Commands"
  14. title changed to:
    New command "timerate": measurement of execution time
    
  15. type changed to: "RFE"