Skip to content

Instantly share code, notes, and snippets.

@ology
Created June 10, 2023 20:08
Show Gist options
  • Save ology/c49ceccd3b76ec0829401c2e0a47d6a5 to your computer and use it in GitHub Desktop.
Save ology/c49ceccd3b76ec0829401c2e0a47d6a5 to your computer and use it in GitHub Desktop.
$m->method(); vs $m->$method(); benchmark
#!/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');
}
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