Create a gist now

Instantly share code, notes, and snippets.

@ggl /benchmark.pl
Last active Dec 26, 2015

What would you like to do?
Moo vs. Mo vs. Class::Tiny vs. Mojo::Base
#!/usr/bin/env perl
package Boo;
use Moo;
has blah => ( is => 'ro' );
sub bla {
my ($oh, @ah) = @_;
return join(' ', ucfirst($oh->blah), @ah);
}
1;
package Bo;
use Mo;
has blah => ();
sub bla {
my ($oh, @ah) = @_;
return join(' ', ucfirst($oh->blah), @ah);
}
1;
package Bct;
use strict;
use warnings;
use Class::Tiny qw(blah);
sub bla {
my ($oh, @ah) = @_;
return join(' ', ucfirst($oh->blah), @ah);
}
1;
package Bmb;
use Mojo::Base -base;
has blah => ();
sub bla {
my ($oh, @ah) = @_;
return join(' ', ucfirst($oh->blah), @ah);
};
1;
package main;
use Benchmark qw(cmpthese);
cmpthese -1, {
moo => sub {
my $b = Boo->new(blah => 'blablabla');
$b->bla('bla', 'blaaa!');
},
mo => sub {
my $b = Bo->new(blah => 'blablabla');
$b->bla('bla', 'blaaa!');
},
ct => sub {
my $b = Bct->new(blah => 'blablabla');
$b->bla('bla', 'blaaa!');
},
mb => sub {
my $b = Bmb->new(blah => 'blablabla');
$b->bla('bla', 'blaaa!');
}
};
package Bla;
use Mo;
has blah => ();
sub bla {
my ($oh, @ah) = @_;
return join(' ', ucfirst($oh->blah), @ah);
}
1;
package main;
my $b = Bla->new(blah => 'blablabla');
print $b->bla('bla', 'blaaa!') . "\n";
package Blah;
use strict;
use warnings;
use Class::Tiny qw(blah);
sub bla {
my ($oh, @ah) = @_;
return join(' ', ucfirst($oh->blah), @ah);
}
1;
package main;
my $b = Blah->new(blah => 'blablabla');
print $b->bla('bla', 'blaaa!') . "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment