-
-
Save FROGGS/d830a84c4bb9f6b2fe07 to your computer and use it in GitHub Desktop.
optimize sort($, $)
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 d22ccfb..3102c1f 100644 | |
--- a/src/core/Any.pm | |
+++ b/src/core/Any.pm | |
@@ -507,6 +507,12 @@ proto uniq(|) { * } | |
multi uniq(*@values) { @values.uniq } | |
proto sub sort(|) {*} | |
+multi sub sort(Callable $a, $b, $c) { | |
+ $a($b, $c) | |
+} | |
+multi sub sort(Mu \a, Mu \b) { | |
+ a cmp b | |
+} | |
multi sub sort(*@values) { | |
@values.at_pos(0).^does(Callable) | |
?? do { my $cmp := @values.shift; @values.sort($cmp) } |
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
$ time perl6 -e 'sort(2, 1) for ^100000' # 100.000 | |
real 0m8.487s | |
user 0m8.321s | |
sys 0m0.144s |
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
$ time perl6 -e 'sort(2, 1) for ^10000' # 10.000 | |
real 0m16.707s | |
user 0m16.525s | |
sys 0m0.152s | |
$ time perl6 -e 'sort(2, 1) for ^100000' # 100.000 | |
real 2m47.941s | |
user 2m47.462s | |
sys 0m0.288s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment