-
-
Save ology/c49ceccd3b76ec0829401c2e0a47d6a5 to your computer and use it in GitHub Desktop.
$m->method(); vs $m->$method(); benchmark
This file contains hidden or 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
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Benchmark; | |
use lib map { "$ENV{HOME}/sandbox/$_/lib" } qw(Music-FretboardDiagram); | |
use Music::FretboardDiagram (); | |
my $count = shift || 100_000_000; | |
my $m = Music::FretboardDiagram->new(chord => 'x02220'); | |
timethese($count, { | |
raw_method => \&raw_method, | |
var_method => \&var_method, | |
}); | |
sub raw_method { | |
my $x = $m->spec_to_notes('x02220'); | |
} | |
sub var_method { | |
my $method = 'spec_to_notes'; | |
my $x = $m->$method('x02220'); | |
} |
This file contains hidden or 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
Benchmark: timing 100000000 iterations of raw_method, var_method... | |
raw_method: 535 wallclock secs (535.25 usr + 0.02 sys = 535.27 CPU) @ 186821.60/s (n=100000000) | |
var_method: 544 wallclock secs (543.73 usr + 0.08 sys = 543.81 CPU) @ 183887.75/s (n=100000000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment