Created
October 23, 2011 17:35
-
-
Save moritz/1307619 to your computer and use it in GitHub Desktop.
Native int postcircumifx:<[ ]>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/core/Any.pm b/src/core/Any.pm | |
index a0476f6..d5399b5 100644 | |
--- a/src/core/Any.pm | |
+++ b/src/core/Any.pm | |
@@ -112,6 +112,10 @@ my class Any { | |
fail "Cannot use negative index $pos on {self.WHAT.perl}" if $pos < 0; | |
self.at_pos($pos) | |
} | |
+ multi method postcircumfix:<[ ]>(int $pos) is rw { | |
+ fail "Cannot use negative index $pos on {self.WHAT.perl}" if $pos < 0; | |
+ self.at_pos($pos) | |
+ } | |
multi method postcircumfix:<[ ]>(Positional $pos) is rw { | |
my $list = $pos.flat; | |
$list.gimme(*); | |
diff --git a/src/core/List.pm b/src/core/List.pm | |
index d4f975f..a944873 100644 | |
--- a/src/core/List.pm | |
+++ b/src/core/List.pm | |
@@ -47,12 +47,18 @@ my class List does Positional { | |
nqp::p6parcel($rpa, Any); | |
} | |
- method at_pos($pos is copy) is rw { | |
+ proto method at_pos($) { * } | |
+ multi method at_pos($pos is copy) is rw { | |
$pos = $pos.Int; | |
self.exists($pos) | |
?? nqp::atpos($!items, nqp::unbox_i($pos)) | |
!! Nil | |
} | |
+ multi method at_pos(int $pos) is rw { | |
+ self.exists($pos) | |
+ ?? nqp::atpos($!items, $pos) | |
+ !! Nil; | |
+ } | |
method eager() { self.gimme(*); self } | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my @a = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10); | |
loop (my int $i = 0; $i < 10_000; $i = $i + 1) { | |
loop (my int $j = 0; $j < 10; $j = $j + 1) { | |
eager @a[$j]; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my @patched = (26.470, 26.127, 26.235, 25.836, 26.133); | |
my @original = (26.265, 25.648, 26.745, 26.045, 26.805); | |
sub avg(*@a) { | |
([+] @a) / @a.elems; | |
} | |
sub std(*@a) { | |
sqrt( avg(@a X** 2) - avg(@a) ** 2); | |
} | |
my $avg_p = avg @patched; | |
my $std_p = std @patched; | |
my $avg_o = avg @original; | |
my $std_o = std @original; | |
my $std = ($std_p + $std_o) / sqrt(2); | |
my $sigmas = abs($avg_p - $avg_o) / $std; | |
say "Original: $avg_o ± $std_o"; | |
say "Patched: $avg_p ± $std_p"; | |
say ($avg_o < $avg_p) ?? 'original' !! 'patched', | |
' version is faster by ', $sigmas, 'σ'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original: 26.3016 ± 0.434601242520083 | |
Patched: 26.1602 ± 0.20421498475871 | |
patched version is faster by 0.313031806614212σ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment