[Kstars-devel] Simple timing tool

James Bowlin bowlin at mindspring.com
Fri Jun 16 17:23:15 CEST 2006


Sometimes these timing measurements can be maddening.  Often what we want
is the average over many draw cycles yet it is easier to add code that
just times every cycle.  Here is a simple Perl script that will take
a series of timing measurements as input and calculate the averages.
If you have trouble hacking it to fit your data, I'll be glad to help.


#!/usr/bin/perl
use strict;

my (%time, %count);

while (<>) {
    m/^\s*#/ and do { print; next };
    m/^\s*$/ and do { print; next };
    m/^(.*?)\s*(\d+)(?:\s*ms)?$/ or next;
    $time{$1} += $2;
    $count{$1}++;
}

for my $name (sort { $time{$b} <=> $time{$a} } keys %time) {
    my $time = $time{$name};
    my $count = $count{$name};
    printf("%15s: %6d / %4d = %8.2f\n", $name, $time, $count, $time/$count);
}
__END__


Sample Input:
#This is the timing for drawing the milkyway outline 100 times in ms.

getXY() took 531
XYZ took 419
getXY() took 520
XYZ took 415
getXY() took 529
XYZ took 445
[ more lines like this snipped]


Sample Output:
# This is the timing for drawing the milkyway outline 100 times in ms.

   getXY() took:   6137 /   11 =   557.91
       XYZ took:   4951 /   11 =   450.09


-- 
Peace, James


More information about the Kstars-devel mailing list