Skip to content

Instantly share code, notes, and snippets.

@ronaldxs
Last active June 27, 2017 17:04
Show Gist options
  • Save ronaldxs/97c0118cffe486f604c74fd686c113f8 to your computer and use it in GitHub Desktop.
Save ronaldxs/97c0118cffe486f604c74fd686c113f8 to your computer and use it in GitHub Desktop.
use MONKEY-SEE-NO-EVAL;
my $simple_arith_sub = q:to/END_SIMPLE_ARITH_SUB/;
sub {
my $r = 0;
for (1..10_000_000) {
$r += 1 + $r % 3
}
print $r, "\n";
}
END_SIMPLE_ARITH_SUB
my &simple_arith_sub_any = EVAL $simple_arith_sub;
my &simple_arith_sub_Int = EVAL $simple_arith_sub.subst(/'my $'/, 'my Int $');
my &simple_arith_sub_int = EVAL $simple_arith_sub.subst(/'my $'/, 'my int $');
my &simple_arith_sub_p5 = EVAL $simple_arith_sub.subst(/'}'\s*$/,
'for my $i (0) {} # throw syntax error if not Perl 5
}'), :lang<Perl5>;
for (
<p5> => &simple_arith_sub_p5,
<any> => &simple_arith_sub_any,
<Int-obj> => &simple_arith_sub_Int,
<int> => &simple_arith_sub_int
) -> $p {
($p.value)();
say $p.key, ' ', now - ENTER now;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment