Skip to content

Instantly share code, notes, and snippets.

@zoffixznet
Created October 1, 2016 12:44
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 zoffixznet/f72faa3f78f52e718e9ea6ef6d194e8f to your computer and use it in GitHub Desktop.
Save zoffixznet/f72faa3f78f52e718e9ea6ef6d194e8f to your computer and use it in GitHub Desktop.
use nqp;
# use Foo;
use Test;
use MONKEY-TYPING;
augment class Array {
multi method foo1 (Int:D $o, Whatever $x, **@a) { self.foo1: $o, $x, @a }
multi method foo1 (Int:D $o, Callable:D $x, **@a) { self.foo1: $o, $x, @a }
multi method foo1 (Int:D $o, Int:D $x, **@a) { self.foo1: $o, $x, @a }
multi method foo1 (Whatever $o, Whatever $x, **@a) { self.foo1: $o, $x, @a }
multi method foo1 (Whatever $o, Callable:D $x, **@a) { self.foo1: $o, $x, @a }
multi method foo1 (Whatever $o, Int:D $x, **@a) { self.foo1: $o, $x, @a }
multi method foo1 (Callable:D $o, Whatever $x, **@a) { self.foo1: $o, $x, @a }
multi method foo1 (Callable:D $o, Callable:D $x, **@a) { self.foo1: $o, $x, @a }
multi method foo1 (Callable:D $o, Int:D $x, **@a) { self.foo1: $o, $x, @a }
multi method foo1 () {}
multi method foo1 (Whatever) {}
multi method foo1 (Callable:D $offset) {}
multi method foo1 (Int:D $offset) {}
multi method foo1 (Whatever, Whatever) {}
multi method foo1 (Whatever, Int:D $size) {}
multi method foo1 (Callable:D $offset, Callable:D $size) {}
multi method foo1 (Callable:D $offset, Whatever) {}
multi method foo1 (Callable:D $offset, Int:D $size) {}
multi method foo1 (Int:D $offset, Whatever) {}
multi method foo1 (Int:D $offset, Callable:D $size) {}
multi method foo1 (Int:D $offset, Int:D $size) {}
multi method foo1 ($offset, Whatever $size, **@new) {}
multi method foo1 ($offset, Callable:D $size, **@new) {}
multi method foo1 ($offset, Int:D $size, **@new) {}
multi method foo1 (Whatever, Whatever, @new) {}
multi method foo1 (Whatever, Int:D $size, @new) {}
multi method foo1 (Callable:D $offset, Callable:D $size, @new) {}
multi method foo1 (Callable:D $offset, Whatever, @new) {}
multi method foo1 (Callable:D $offset, Int:D $size, @new) {}
multi method foo2 ($x, $y, **@a) {
given self.^lookup('foo2').cando( \($x, $y, @a) )[0] {
.signature eqv &?BLOCK.signature and die;
$_($x, $y, @a);
}
}
multi method foo2 () {}
multi method foo2 (Whatever) {}
multi method foo2 (Callable:D $offset) {}
multi method foo2 (Int:D $offset) {}
multi method foo2 (Whatever, Whatever) {}
multi method foo2 (Whatever, Int:D $size) {}
multi method foo2 (Callable:D $offset, Callable:D $size) {}
multi method foo2 (Callable:D $offset, Whatever) {}
multi method foo2 (Callable:D $offset, Int:D $size) {}
multi method foo2 (Int:D $offset, Whatever) {}
multi method foo2 (Int:D $offset, Callable:D $size) {}
multi method foo2 (Int:D $offset, Int:D $size) {}
multi method foo2 ($offset, Whatever $size, **@new) {}
multi method foo2 ($offset, Callable:D $size, **@new) {}
multi method foo2 ($offset, Int:D $size, **@new) {}
multi method foo2 (Whatever, Whatever, @new) {}
multi method foo2 (Whatever, Int:D $size, @new) {}
multi method foo2 (Callable:D $offset, Callable:D $size, @new) {}
multi method foo2 (Callable:D $offset, Whatever, @new) {}
multi method foo2 (Callable:D $offset, Int:D $size, @new) {}
}
sub timethese ($n, %what) {
my %results;
for %what.kv -> $name, &code {
my $start = now;
code for ^$n;
%results{$name} = now - $start;
}
%results;
}
say "starting";
my %res = timethese 10, {
before => &before,
after => &after,
};
say "Before: %res<before>";
say " After: %res<after>";
printf " Diff: %.2f%%\n",
100*(%res<before> - %res<after>) / max(%res<before>,%res<after>);
sub before {
[].foo1: 0, 42, 1, 2, 3;
}
sub after {
[].foo2: 0, 42, 1, 2, 3;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment