Skip to content

Instantly share code, notes, and snippets.

@samcv
Created August 24, 2017 00:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samcv/ecacbea31a89e14d5d0b1dd41dfe118e to your computer and use it in GitHub Desktop.
Save samcv/ecacbea31a89e14d5d0b1dd41dfe118e to your computer and use it in GitHub Desktop.
my $*test-count = 0;
my @results;
my $b1 = { .defined };
my $b2 = { 0 ≤ $_ };
test-it({
my $b = 'a' x 999999 ~ 'b';
$b ~~ /b/ for ^400;
}, $b1, 10000);
test-it({
my $b = 'a' x 999999 ~ 'b';
use nqp;
nqp::index($b, 'b', 0);
},
$b2,
10 );
sub test-it (&code, &eval, Int:D $times = 1) {
my $t1 = now;
my $rtrn;
for ^$times {
$rtrn = &code;
}
die unless &eval($rtrn);
my $tot = now - $t1;
@results.push: $tot;
say "Test {++$*test-count}: $tot s";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment