Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use user time in benchmark script
  • Loading branch information
sorear committed May 30, 2011
1 parent f7b5a9c commit 94d21c4
Showing 1 changed file with 19 additions and 73 deletions.
92 changes: 19 additions & 73 deletions perf/std-20110528.pl6
@@ -1,82 +1,28 @@
use JSYNC;

sub calibrate() {
my $start = now.to-posix.[0];
my $i = -1000000;
my $f = sub () {};
$f() while $i++;
my $end = now.to-posix.[0];
($end - $start) / 1000000;
sub timethis($nr, $fun) {
my $i = -$nr;
my $start = times[0];
$fun() while $i++;
my $end = times[0];
($end - $start) / $nr;
}

my $base = calibrate();
my $base1 = timethis(1000000, sub () {});
my $base2 = timethis(1000000, sub () {});
my $avg = ($base1 + $base2) / 2;
say "null check: rd = {abs ($base1 - $base2) / $avg} ($base1 $base2)";

sub bench($name, $nr, $f) {
my $start = now.to-posix.[0];
my $i = -$nr;
$f() while $i++;
my $end = now.to-posix.[0];
say "$name = {($end - $start) / $nr - $base} [raw {$end-$start} for $nr]";
my $time = timethis($nr, $f);
say "$name = {($time - $avg)*1e6}µs [{$time*$nr}s / $nr]";
}

bench "nulling test", 1000000, sub () {};
# {
# my @l;
# bench "iterate empty list", 1000000, sub () { for @l { } };
# }

my @x; my $y; my $z; my %h;
bench "scalar assign", 1000000, sub () { $y = 1; $y = 2; $y = 3; $y = 4; $y = 5; $y = 6; $y = 7; $y = 8; $y = 9; $y = 10 };
bench "list assign (Parcel)", 1000000, sub () { ($y,$z) = ($z,$y) };
bench "list assign (Array)", 1000000, sub () { @x = 1, 2, 3 };
bench "list assign (Hash)", 1000000, sub () { %h = "a", 1, "b", 2 };
bench 'head assign (&head)', 1000000, sub () { $y = head((1,2,3)) };
bench 'head assign (Parcel)', 1000000, sub () { ($y,) = (1,2,3) };

# my %h; my $x;
# bench "Hash.delete-key", 1000000, sub () { %h<foo>:delete };
# bench "Any.delete-key", 1000000, sub () { $x<foo>:delete };
# bench "Bool.Numeric", 1000000, sub () { +True };
my @arr;

# my ($x, $y);
# bench "Parcel.LISTSTORE", 1000000, sub () { ($x,$y) = ($y,$x) };
# {
# "foo" ~~ /f(.)/;
# bench '$<x>', 1000000, sub () { $0 };
# }
#
# my $str = "0";
# $str ~= $str for ^18;
# say $str.chars;
# # $str = substr($str,0,1000000);
#
# my grammar GTest {
# token TOP { <.bit>* }
# token bit { . }
# }
#
# bench "grammar", 1, sub () { GTest.parse($str) };
# {
# my class GAct0 {
# }
# bench "grammar (no action)", 1, sub () { GTest.parse($str, :actions(GAct0)) };
# }
#
# {
# my class GAct1 {
# method bit($ ) { }
# }
# bench "grammar (empty action)", 1, sub () { GTest.parse($str, :actions(GAct1)) };
# }
#
# {
# my class GAct2 {
# method FALLBACK($ , $ ) { }
# }
# bench "grammar (fallback action)", 1, sub () { GTest.parse($str, :actions(GAct2)) };
# }
#
# bench "Any.exists-key", 1000000, sub () { Any<foo>:exists };
#
# my $arr = [1];
# bench "JSON array iteration", 1000000, sub () { to-json($arr) };
bench "(zeroing array)", 100000, sub () { @arr = () };
bench "(tenning array)", 100000, sub () { @arr = 0,1,2,3,4,5,6,7,8,9 };
bench "push", 100000, sub () { @arr = (); push @arr, 1; push @arr, 2; push @arr, 3; push @arr, 4; push @arr, 5; push @arr, 6; push @arr, 7; push @arr, 8; push @arr, 9; push @arr, 10; };
bench "unshift", 100000, sub () { @arr = (); unshift @arr, 1; unshift @arr, 2; unshift @arr, 3; unshift @arr, 4; unshift @arr, 5; unshift @arr, 6; unshift @arr, 7; unshift @arr, 8; unshift @arr, 9; unshift @arr, 10; };
bench "pop", 100000, sub () { @arr = 0,1,2,3,4,5,6,7,8,9; pop @arr; pop @arr; pop @arr; pop @arr; pop @arr; pop @arr; pop @arr; pop @arr; pop @arr; pop @arr };
bench "shift", 100000, sub () { @arr = 0,1,2,3,4,5,6,7,8,9; shift @arr; shift @arr; shift @arr; shift @arr; shift @arr; shift @arr; shift @arr; shift @arr; shift @arr; shift @arr };

0 comments on commit 94d21c4

Please sign in to comment.