-
-
Save zoffixznet/30ba2fbc0244a9d19395b4c9486bb157 to your computer and use it in GitHub Desktop.
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
Bare: 0.028753594768s | |
Old: 9.173754254014297434905s | |
New: 0.163172s | |
NEW version is 56.22x faster |
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
use Benchy; | |
sub old (\SELF, \b) { | |
nqp::if( | |
nqp::iseq_i(0, $_ := nqp::add_i( | |
nqp::istype(b, Numeric), nqp::istype(b, Numeric))) | |
|| nqp::iseq_i($_, 2), | |
SELF.Int.ACCEPTS(b) && SELF.Str.ACCEPTS(b), | |
nqp::if( | |
nqp::istype(b, Str), | |
SELF.Str.ACCEPTS(b), | |
SELF.Int.ACCEPTS(b))) | |
} | |
sub new (\SELF, \b) { | |
nqp::if( | |
nqp::istype(b, Numeric), | |
nqp::if( | |
nqp::istype(b, Str), | |
SELF.Int.ACCEPTS(b) && SELF.Str.ACCEPTS(b), | |
SELF.Int.ACCEPTS(b)), | |
nqp::if( | |
nqp::istype(b, Str), | |
SELF.Str.ACCEPTS(b), | |
SELF.Str.ACCEPTS(b) && SELF.Int.ACCEPTS(b))) | |
} | |
class Foo { method Str { '' }; method Int { 1 } } | |
b 10000, | |
{ | |
$ = old <1>, 1; | |
$ = old <1>, '1'; | |
$ = old <1>, <1>; | |
$ = old <1>, Foo.new; | |
}, | |
{ | |
$ = new <1>, 1; | |
$ = new <1>, '1'; | |
$ = new <1>, <1>; | |
$ = new <1>, Foo.new; | |
}, | |
{ | |
$ = <1>; $ = 1; | |
$ = <1>; $ = '1'; | |
$ = <1>; $ = <1>; | |
$ = <1>; $ = Foo.new; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment