-
-
Save ugexe/707df8eddc1f055fdc2ca8c27fceba48 to your computer and use it in GitHub Desktop.
polyglot perl 5/6 benchmark
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 @ARGV = ("123456789"); | |
sub to_int($_) { ("0" and (return Int($_[0])) or (return int($_[0]))) }; | |
sub from_base35 { | |
my ($state, $result, $dict, $base35) = (1, "", {}, @_[0]); | |
$dict{$_} = $_ for "1".."9"; | |
$dict{$_} = ord($_) - 55 for "A".."Y"; | |
for (reverse grep &{ sub ($_) { $_ ne "" } }.(), split("", $base35)) { | |
$result += $state * $dict{$_}; | |
$state *= 35; | |
}; | |
$result | |
} | |
sub to_base35 { | |
my ($result, $dict, $base10) = ("", {}, @_[0]); | |
$dict{$_} = $_ for "1".."9"; | |
$dict{ord($_) - 55} = $_ for "A".."Y"; | |
while ($base10 > 0) { | |
$result = join("", $dict{to_int($base10 % 35)}, $result); | |
$base10 = to_int($base10 / 35); | |
} | |
$result; | |
} | |
for (1..100000) { | |
my $to = to_base35(@ARGV[0]); | |
my $from = from_base35($to); | |
} |
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 perl benchmark.pl | |
real 1m2.839s | |
user 1m2.693s | |
sys 0m0.063s | |
$ time perl6 benchmark.pl | |
real 1m12.175s | |
user 1m12.214s | |
sys 0m0.200s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment