perl6-bench version d177e1a (ignoring startup time and compile time)

Toggles
[ Code ]
Perl 6: my $z = 0;
NQP: my $z := 0;
Perl 5: my $z = 0;
[ Code ]
Perl 6: say "Hello, World!"
NQP: say("Hello, World!")
Perl 5: say "Hello, World!"
[ Code ]
Perl 6: my $i = 0; while (++$i <= SCALE) { }; say $i;
NQP: my $i := 0; while ($i := $i + 1) <= SCALE { }; say($i);
Perl 5: my $i = 0; while (++$i <= SCALE) { }; say $i;
[ Code ]
Perl 6: my int $i = 0; while ($i = $i + 1) <= SCALE { }; say $i;
NQP: my int $i := 0; while ($i := $i + 1) <= SCALE { }; say($i);
Perl 5: use integer; my $i = 0; while (++$i <= SCALE) { }; say $i;
[ Code ]
Perl 6: my $a := 0; my $b := 1; my $i = 0; while (++$i <= SCALE) { $a := $b }; say $a;
NQP: my $a := 0; my $b := 1; my $i := 0; while ($i := $i + 1) <= SCALE { $a := $b }; say($a);
Perl 5: use Data::Alias; alias my $a = 0; alias my $b = 1; my $i = 0; while (++$i <= SCALE) { alias $a = $b }; say $a;
[ Code ]
Perl 6: my $s = ""; my $i = 0; while (++$i <= SCALE) { $s ~= "x" }; say $s.chars;
NQP: my $s := ""; my $i := 0; while ($i := $i + 1) <= SCALE { $s := $s ~ "x" }; say(nqp::chars($s));
Perl 5: my $s = ""; my $i = 0; while (++$i <= SCALE) { $s .= "x" }; say length($s);
[ Code ]
Perl 6: my str $s = ""; my int $i = 0; while ($i = $i + 1) <= SCALE { $s = $s ~ "x" }; say $s.chars;
NQP: my str $s := ""; my int $i := 0; while ($i := $i + 1) <= SCALE { $s := $s ~ "x" }; say(nqp::chars($s));
Perl 5: use integer; my $s = ""; my $i = 0; while (++$i <= SCALE) { $s .= "x" }; say length($s);
[ Code ]
Perl 6: my $i = 0; my $s = ~$i; while (++$i <= SCALE) { $s = ~$i }; say $s;
NQP: my $i := 0; my $s := ~$i; while ($i := $i + 1) <= SCALE { $s := ~$i }; say($s);
Perl 5: my $i = 0; my $s = "$i"; while (++$i <= SCALE) { $s = "$i" }; say $s;
[ Code ]
Perl 6: my int $i = 0; my str $s = ~$i; while ($i = $i + 1) <= SCALE { $s = ~$i }; say $s;
NQP: my int $i := 0; my str $s := ~$i; while ($i := $i + 1) <= SCALE { $s := ~$i }; say($s);
Perl 5: use integer; my $i = 0; my $s = "$i"; while (++$i <= SCALE) { $s = "$i" }; say $s;
[ Code ]
Perl 6: my $s = ""; my $i = 0; while (++$i <= SCALE) { $s ~= $i }
NQP: my $s := ""; my $i := 0; while ($i := $i + 1) <= SCALE { $s := $s ~ $i }
Perl 5: my $s = ""; my $i = 0; while (++$i <= SCALE) { $s .= $i }
[ Code ]
Perl 6: my str $s = ""; my int $i = 0; while ($i = $i + 1) <= SCALE { $s = $s ~ $i }
NQP: my str $s := ""; my int $i := 0; while ($i := $i + 1) <= SCALE { $s := $s ~ $i }
Perl 5: use integer; my $s = ""; my $i = 0; while (++$i <= SCALE) { $s .= $i }
[ Code ]
Perl 6: my @a; my $i = 0; while (++$i <= SCALE) { @a.push("x") }; my $s = @a.join; say $s.chars;
NQP: my @a; my $i := 0; while ($i := $i + 1) <= SCALE { nqp::push(@a, "x"); }; my $s := nqp::join("",@a); say(nqp::chars($s));
Perl 5: my @a; my $i = 0; while (++$i <= SCALE) { push @a, "x" }; my $s = join "" => @a; say length($s);
[ Code ]
Perl 6: my @a; my $i = 0; while (++$i <= SCALE) { push @a, 1 }; say +@a;
NQP: my @a; my $i := 0; while ($i := $i + 1) <= SCALE { nqp::push(@a, 1) }; say(+@a);
Perl 5: my @a; my $i = 0; while (++$i <= SCALE) { push @a, 1 }; say scalar @a;
[ Code ]
Perl 6: my @a; @a.push(42); my $i = 0; while (++$i <= SCALE) { @a.push(@a) }; say +@a;
NQP: my @a; nqp::push(@a, 42); my $i := 0; while ($i := $i + 1) <= SCALE { my $elems := nqp::elems(@a); my $j := 0; while $j < $elems { nqp::push(@a, @a[$j]); $j++; } }; say(+@a);
Perl 5: my @a; push @a, 42; my $i = 0; while (++$i <= SCALE) { push @a, @a }; say scalar @a;
[ Code ]
Perl 6: my @a; my $i = 0; @a[$i] = $i; while (++$i <= SCALE) { @a[ $i ] = $i }; say @a[*-1];
NQP: my @a; my $i := 0; @a[$i] := $i; while ($i := $i + 1) <= SCALE { @a[ $i ] := $i }; say(@a[@a - 1]);
Perl 5: my @a; my $i = 0; $a[$i] = $i; while (++$i <= SCALE) { $a[ $i ] = $i }; say $a[-1];
[ Code ]
Perl 6: my %h; my $i = 0; %h{$i} = $i; while (++$i <= SCALE) { %h{ $i } = $i }; say %h{$i - 1};
NQP: my %h; my $i := 0; %h{$i} := $i; while ($i := $i + 1) <= SCALE { %h{ $i } := $i }; say(%h{$i - 1});
Perl 5: my %h; my $i = 0; $h{$i} = $i; while (++$i <= SCALE) { $h{ $i } = $i }; say $h{$i - 1};
[ Code ]
Perl 6: my $i = -SCALE || exit(0); Nil while ++$i; say $i;
NQP: my $i := -SCALE || nqp::exit(0); () while $i := $i + 1; say($i);
Perl 5: my $i = -SCALE || exit(0); () while ++$i; say $i;
[ Code ]
Perl 6: my int $i = -SCALE || exit(0); Nil while $i = $i + 1; say $i;
NQP: my int $i := -SCALE || nqp::exit(0); () while $i := $i + 1; say($i);
Perl 5: use integer; my $i = -SCALE || exit(0); () while ++$i; say $i;
[ Code ]
Perl 6: loop (my $i = 1; $i <= SCALE; ++$i) { }; say $i;
Perl 5: for (my $i = 1; $i <= SCALE; ++$i) { }; say $i;
[ Code ]
Perl 6: loop (my int $i = 1; $i <= SCALE; $i = $i + 1) { }; say $i;
Perl 5: use integer; for (my $i = 1; $i <= SCALE; ++$i) { }; say $i;
[ Code ]
Perl 6: for (1 .. SCALE) { }; say SCALE;
Perl 5: for (1 .. SCALE) { }; say SCALE;
[ Code ]
Perl 6: my $a := 0; my $b := 1; for (1 .. SCALE) { $a := $b; }; say $a;
Perl 5: use Data::Alias; alias my $a = 0; alias my $b = 1; for (1 .. SCALE) { alias $a = $b; }; say $a;
[ Code ]
Perl 6: my $a = 0; my $b = 1; for (1 .. SCALE) { $a = $b; }; say $a;
Perl 5: my $a = 0; my $b = 1; for (1 .. SCALE) { $a = $b; }; say $a;
[ Code ]
Perl 6: my int $a = 0; my int $b = 1; for (1 .. SCALE) { $a = $b; }; say $a;
Perl 5: use integer; my $a = 0; my $b = 1; for (1 .. SCALE) { $a = $b; }; say $a;
[ Code ]
Perl 6: my $i = 0; for (1 .. SCALE) { $i++ }; say $i;
Perl 5: my $i = 0; for (1 .. SCALE) { $i++ }; say $i;
[ Code ]
Perl 6: my int $i = 0; for (1 .. SCALE) { $i = $i + 1 }; say $i;
Perl 5: use integer; my $i = 0; for (1 .. SCALE) { $i++ }; say $i;
[ Code ]
Perl 6: my $s = ""; for (1 .. SCALE) { $s ~= "x" }; say $s.chars;
Perl 5: my $s = ""; for (1 .. SCALE) { $s .= "x" }; say length($s);
[ Code ]
Perl 6: my str $s = ""; for (1 .. SCALE) { $s = $s ~ "x" }; say $s.chars;
Perl 5: use integer; my $s = ""; for (1 .. SCALE) { $s .= "x" }; say length($s);
[ Code ]
Perl 6: my $x = "a"; my $y = ""; for (1 .. SCALE) { $y ~= ($x ~ $x) }; say $y.chars;
Perl 5: my $x = "a"; my $y = ""; for (1 .. SCALE) { $y .= ($x . $x) }; say length($y);
[ Code ]
Perl 6: my str $x = "a"; my str $y = ""; for (1 .. SCALE) { $y = $y ~ $x ~ $x }; say $y.chars;
Perl 5: use integer; my $x = "a"; my $y = ""; for (1 .. SCALE) { $y .= ($x . $x) }; say length($y);
[ Code ]
Perl 6: my @a; for (1 .. SCALE) { push @a, 1 }; say +@a;
Perl 5: my @a; for (1 .. SCALE) { push @a, 1 }; say scalar @a;
[ Code ]
Perl 6: my @a; @a[ $_ ] = $_ for 0 .. SCALE; say @a[SCALE];
Perl 5: my @a; $a[ $_ ] = $_ for 0 .. SCALE; say @a[SCALE];
[ Code ]
Perl 6: my %h; %h{ $_ } = $_ for 0 .. SCALE; say %h<SCALE>;
Perl 5: my %h; $h{ $_ } = $_ for 0 .. SCALE; say $h{SCALE};
[ Code ]
Perl 6: say [+] 1 .. SCALE;
Perl 5: use List::Util "reduce"; say reduce { $a + $b } 1 .. SCALE;
[ Code ]
Perl 6: say [+] (1 .. SCALE).comb>>.Int;
Perl 5: use List::Util "reduce"; say reduce { $a + $b } map { 0+$_ } map { split "" } 1 .. SCALE;
[ Code ]
Perl 6: my $match = 1 == any(1 .. SCALE); my $fail = 0 == any(1 .. SCALE); say "{+?$match} {+?$fail}"
Perl 5: my $match = grep { 1 == $_ } 1 .. SCALE; my $fail = grep { 0 == $_ } 1 .. SCALE; say "$match $fail"
[ Code ]
Perl 6: my $s = " " x SCALE ~ "x" x SCALE ~ " " x SCALE; my $result = ""; $result = $s.trim for 1 .. SCALE; say $result.chars;
Perl 5: my $s = " " x SCALE . "x" x SCALE . " " x SCALE; my $result = ""; ($result) = $s =~ /^\s*(.*?)\s*$/s for 1 .. SCALE; say length($result);
[ Code ]
Perl 6: my $s = (1 .. SCALE).join: ", "; my $i; my @s = $s.split(", ") while ++$i <= SCALE; say +@s;
NQP: my @i; my $i := 0; while ($i := $i + 1) <= SCALE { nqp::push(@i, ~$i); }; my $s := nqp::join(", ", @i); $i := 0; my @s; while ($i := $i + 1) <= SCALE { @s := nqp::split(", ", $s) }; say(+@s);
Perl 5: my $s = join ", " => 1 .. SCALE; my $i; my @s; @s = split ", " => $s while ++$i <= SCALE; say scalar @s;
[ Code ]
Perl 6: my $s = (1 .. SCALE).join: ", "; my @s = $s.split(/\s*\,\s*/) for 1 .. SCALE; say +@s;
Perl 5: my $s = join ", " => 1 .. SCALE; my @s = split /\s*,\s*/ => $s for 1 .. SCALE; say scalar @s;
[ Code ]
Perl 6: my $y = chr(SCALE); my $n = chr(SCALE + 1); my $i = 0; while (++$i <= SCALE) {$y ~~ /<[\c0..\c[SCALE]]>/; $n ~~ /<[\c0..\c[SCALE]]>/ }
NQP: my $y := nqp::chr(SCALE); my $n := nqp::chr(SCALE + 1); my $i := 0; while ($i := $i + 1) <= SCALE { $y ~~ /<[\c0..\c[SCALE]]>/; $n ~~ /<[\c0..\c[SCALE]]>/ }
Perl 5: my $y = chr(SCALE); my $n = chr(SCALE + 1); my $c = sprintf("%x",SCALE); my $reg="[\x00-\x{$c}]"; my $i = 0; while (++$i <= SCALE) { $y ~~ /$reg/; $n ~~ /$reg/; }
[ Code ]
Perl 6: my $y = chr(SCALE); my $n = chr(SCALE + 1); my $i = 0; while (++$i <= SCALE) {$y ~~ /:i<[\c0..\c[SCALE]]>/; $n ~~ /:i<[\c0..\c[SCALE]]>/ }
NQP: my $y := nqp::chr(SCALE); my $n := nqp::chr(SCALE + 1); my $i := 0; while ($i := $i + 1) <= SCALE { $y ~~ /:i<[\c0..\c[SCALE]]>/; $n ~~ /:i<[\c0..\c[SCALE]]>/ }
Perl 5: my $y = chr(SCALE); my $n = chr(SCALE + 1); my $c = sprintf("%x",SCALE); my $reg="[\x00-\x{$c}]"; my $i = 0; while (++$i <= SCALE) { $y ~~ /$reg/i; $n ~~ /$reg/i; }
[ Code ]
Perl 6: my $k = 0; my $i = 1; while ($i <= SCALE) { my $j = 1; while ($j <= SCALE) { $k = $i + $j; ++$j }; ++$i }; say $k
NQP: my $k := 0; my $i := 1; while ($i <= SCALE) { my $j := 1; while ($j <= SCALE) { $k := $i + $j; $j := $j + 1 }; $i := $i + 1 }; say($k)
Perl 5: my $k = 0; my $i = 1; while ($i <= SCALE) { my $j = 1; while ($j <= SCALE) { $k = $i + $j; ++$j }; ++$i }; say $k
[ Code ]
Perl 6: my int $k = 0; my int $i = 1; while ($i <= SCALE) { my int $j = 1; while ($j <= SCALE) { $k = $i + $j; $j = $j + 1 }; $i = $i + 1 }; say $k
NQP: my int $k := 0; my int $i := 1; while ($i <= SCALE) { my int $j := 1; while ($j <= SCALE) { $k += $i + $j; $j := $j + 1 }; $i := $i + 1 }; say($k)
Perl 5: use integer; my $k = 0; my $i = 1; while ($i <= SCALE) { my $j = 1; while ($j <= SCALE) { $k = $i + $j; ++$j }; ++$i }; say $k
[ Code ]
Perl 6: my $k = 0; loop (my $i = 1; $i <= SCALE; ++$i) { loop (my $j = 1; $j <= SCALE; ++$j) { $k = $i + $j } }; say $k;
Perl 5: my $k = 0; for (my $i = 1; $i <= SCALE; ++$i) { for (my $j = 1; $j <= SCALE; ++$j) { $k = $i + $j } }; say $k;
[ Code ]
Perl 6: my int $k = 0; loop (my int $i = 1; $i <= SCALE; $i = $i + 1) { loop (my int $j = 1; $j <= SCALE; $j = $j + 1) { $k = $i + $j } }; say $k;
Perl 5: use integer; my $k = 0; for (my $i = 1; $i <= SCALE; ++$i) { for (my $j = 1; $j <= SCALE; ++$j) { $k = $i + $j } }; say $k;
[ Code ]
Perl 6: my $k = 0; for 1 .. SCALE -> $i { for 1 .. SCALE -> $j { $k = $i + $j }; Nil }; say $k;
Perl 5: my $k = 0; for my $i (1 .. SCALE) { for my $j (1 .. SCALE) { $k = $i + $j }; 1 }; say $k;
[ Code ]
Perl 6: my $k = 0; for flat(1 .. SCALE X 1 .. SCALE) -> $i, $j { $k = $i + $j }; say $k;
NQP: my $k := 0; sub mk2d($h, $w) { my $x := 1; my $y := 1; sub () { return () if $y > $h; my @c := ($y, $x); if ++$x > $w { $x := 1; ++$y; }; @c } }; my $it := mk2d(SCALE, SCALE); while $it() -> @c { $k := @c[0] + @c[1] }; say($k);
Perl 5: my $k = 0; sub mk2d { my ($h, $w) = @_; my $x = 1; my $y = 1; sub { return if $y > $h; my @c = ($y, $x); if (++$x > $w) { $x = 1; ++$y; }; @c } }; my $it = mk2d(SCALE, SCALE); while (my ($i, $j) = $it->()) { $k = $i + $j }; say $k;
[ Code ]
Perl 6: my $k = 0; for (1 .. SCALE X 1 .. SCALE) -> ($i, $j) { $k = $i + $j }; say $k;
[ Code ]
Perl 6: my (@src, @dst); @dst[0][0] = 0; for flat(1 .. SCALE X 1 ..SCALE) -> $i, $j { @src[$i][$j] = $i + $j }; for flat(1 .. SCALE X 1 .. SCALE) -> $i, $j { @dst[$i][$j] = @src[$i][$j] }; say @dst[SCALE][SCALE];
NQP: sub mk2d($h, $w) { my $x := 1; my $y := 1; sub () { return () if $y > $h; my @c := ($y, $x); if ++$x > $w { $x := 1; ++$y; }; @c } }; my @src; my @dst; my $it := mk2d(SCALE, SCALE); while $it() -> @c { @src[@c[0]] := [] unless @src[@c[0]]; @src[@c[0]][@c[1]] := @c[0] + @c[1] }; $it := mk2d(SCALE, SCALE); while $it() -> @c { @dst[@c[0]] := [] unless @dst[@c[0]]; @dst[@c[0]][@c[1]] := @src[@c[0]][@c[1]] }; say(@dst[SCALE][SCALE]);
Perl 5: sub mk2d { my ($h, $w) = @_; my $x = 1; my $y = 1; sub { return if $y > $h; my @c = ($y, $x); if (++$x > $w) { $x = 1; ++$y; }; @c } }; my (@src, @dst); $dst[0][0] = 0; my $it = mk2d(SCALE, SCALE); while (my ($i, $j) = $it->()) { $src[$i][$j] = $i + $j }; $it = mk2d(SCALE, SCALE); while (my ($i, $j) = $it->()) { $dst[$i][$j] = $src[$i][$j] }; say $dst[SCALE][SCALE];
[ Code ]
Perl 6: my (@src, @dst); @dst[0][0] = 0; for (1 .. SCALE X 1 ..SCALE) -> ($i, $j) { @src[$i][$j] = $i + $j }; for (1 .. SCALE X 1 .. SCALE) -> ($i, $j) { @dst[$i][$j] = @src[$i][$j] }; say @dst[SCALE][SCALE];
[ Code ]
Perl 6: my %h; my $m = 0; for ^SCALE { %h{$_} = $_ }; for %h.kv -> $k, $v { $m += $k == $v }; say $m;
Perl 5: my %h; my $m = 0; for (0 .. (SCALE - 1)) { %h{$_} = $_ }; while (my ($k, $v) = each %h) { $m += $k == $v }; say $m
[ Code ]
Perl 6: my $r = 1.0; for 1 .. SCALE { $r *= $_; $r /= $_ + 1 }; say $r.numerator ~ "/" ~ $r.denominator;
Perl 5: use Math::BigRat; my $r = Math::BigRat->new(1); for (1 .. SCALE) { $r *= $_; $r /= $_ + 1 }; say $r->numerator . "/" . $r->denominator;
[ Code ]
Perl 6: my $r = FatRat.new(0, 1); for 1 .. SCALE { $r += 1 / $_ }; say $r.perl
Perl 5: use Math::BigRat; my $r = Math::BigRat->new(0); for (1 .. SCALE) { $r += Math::BigRat->new(Math::BigInt->new(1), Math::BigInt->new($_)) }; say $r
[ Code ]
Perl 6: my $total = 0; for ^SCALE { $total += rand }; say $total
NQP: my $total := 0; my $i := 0; while $i++ < SCALE { $total := $total + nqp::rand_n(1) }; say($total)
Perl 5: my $total = 0; for (1 .. SCALE) { $total += rand }; say $total
[ Code ]
Perl 6: my @a = 0 xx SCALE; say +@a
Perl 5: my @a = (0) x SCALE; say scalar @a
[ Code ]
Perl 6: $_ = "0" x 100 ~ "foo bar baz"; my $s = "foo bar baz"; loop (my $i = 0; $i < SCALE; $i++) { /$s/ }
Perl 5: $_ = ("0" x 100) . "foo bar baz"; my $s = "foo bar baz"; for (my $i = 0; $i < SCALE; $i++) { /\Q$s\E/ }