Skip to content
This repository
Browse code

Use user time in benchmark script

  • Loading branch information...
commit 94d21c437562e490bc61c95f9d953914afc179a1 1 parent f7b5a9c
sorear authored May 30, 2011

Showing 1 changed file with 19 additions and 73 deletions. Show diff stats Hide diff stats

  1. 92  perf/std-20110528.pl6
92  perf/std-20110528.pl6
... ...
@@ -1,82 +1,28 @@
1 1
 use JSYNC;
2 2
 
3  
-sub calibrate() {
4  
-    my $start = now.to-posix.[0];
5  
-    my $i = -1000000;
6  
-    my $f = sub () {};
7  
-    $f() while $i++;
8  
-    my $end = now.to-posix.[0];
9  
-    ($end - $start) / 1000000;
  3
+sub timethis($nr, $fun) {
  4
+    my $i = -$nr;
  5
+    my $start = times[0];
  6
+    $fun() while $i++;
  7
+    my $end = times[0];
  8
+    ($end - $start) / $nr;
10 9
 }
11 10
 
12  
-my $base = calibrate();
  11
+my $base1 = timethis(1000000, sub () {});
  12
+my $base2 = timethis(1000000, sub () {});
  13
+my $avg = ($base1 + $base2) / 2;
  14
+say "null check: rd = {abs ($base1 - $base2) / $avg}  ($base1 $base2)";
13 15
 
14 16
 sub bench($name, $nr, $f) {
15  
-    my $start = now.to-posix.[0];
16  
-    my $i = -$nr;
17  
-    $f() while $i++;
18  
-    my $end   = now.to-posix.[0];
19  
-    say "$name = {($end - $start) / $nr - $base} [raw {$end-$start} for $nr]";
  17
+    my $time = timethis($nr, $f);
  18
+    say "$name = {($time - $avg)*1e6}µs [{$time*$nr}s / $nr]";
20 19
 }
21 20
 
22  
-bench "nulling test", 1000000, sub () {};
23  
-# {
24  
-#    my @l;
25  
-#    bench "iterate empty list", 1000000, sub () { for @l { } };
26  
-# }
27  
-
28  
-my @x; my $y; my $z; my %h;
29  
-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 };
30  
-bench "list assign (Parcel)", 1000000, sub () { ($y,$z) = ($z,$y) };
31  
-bench "list assign (Array)", 1000000, sub () { @x = 1, 2, 3 };
32  
-bench "list assign (Hash)", 1000000, sub () { %h = "a", 1, "b", 2 };
33  
-bench 'head assign (&head)', 1000000, sub () { $y = head((1,2,3)) };
34  
-bench 'head assign (Parcel)', 1000000, sub () { ($y,) = (1,2,3) };
35  
-
36  
-# my %h; my $x;
37  
-# bench "Hash.delete-key", 1000000, sub () { %h<foo>:delete };
38  
-# bench "Any.delete-key", 1000000, sub () { $x<foo>:delete };
39  
-# bench "Bool.Numeric", 1000000, sub () { +True };
  21
+my @arr;
40 22
 
41  
-# my ($x, $y);
42  
-# bench "Parcel.LISTSTORE", 1000000, sub () { ($x,$y) = ($y,$x) };
43  
-# {
44  
-#     "foo" ~~ /f(.)/;
45  
-#     bench '$<x>', 1000000, sub () { $0 };
46  
-# }
47  
-# 
48  
-# my $str = "0";
49  
-# $str ~= $str for ^18;
50  
-# say $str.chars;
51  
-# # $str = substr($str,0,1000000);
52  
-# 
53  
-# my grammar GTest {
54  
-#     token TOP { <.bit>* }
55  
-#     token bit { . }
56  
-# }
57  
-# 
58  
-# bench "grammar", 1, sub () { GTest.parse($str) };
59  
-# {
60  
-#     my class GAct0 {
61  
-#     }
62  
-#     bench "grammar (no action)", 1, sub () { GTest.parse($str, :actions(GAct0)) };
63  
-# }
64  
-# 
65  
-# {
66  
-#     my class GAct1 {
67  
-#         method bit($ ) { }
68  
-#     }
69  
-#     bench "grammar (empty action)", 1, sub () { GTest.parse($str, :actions(GAct1)) };
70  
-# }
71  
-# 
72  
-# {
73  
-#     my class GAct2 {
74  
-#         method FALLBACK($ , $ ) { }
75  
-#     }
76  
-#     bench "grammar (fallback action)", 1, sub () { GTest.parse($str, :actions(GAct2)) };
77  
-# }
78  
-# 
79  
-# bench "Any.exists-key", 1000000, sub () { Any<foo>:exists };
80  
-# 
81  
-# my $arr = [1];
82  
-# bench "JSON array iteration", 1000000, sub () { to-json($arr) };
  23
+bench "(zeroing array)", 100000, sub () { @arr = () };
  24
+bench "(tenning array)", 100000, sub () { @arr = 0,1,2,3,4,5,6,7,8,9 };
  25
+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; };
  26
+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; };
  27
+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 };
  28
+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 notes on commit 94d21c4

Please sign in to comment.
Something went wrong with that request. Please try again.