Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/perl
use strict;
use warnings;
use Hash::Inflator;
use Hash::AsObject;
use Data::OpenStruct::Deep;
use Test::MockObject;
use Benchmark qw(:hireswallclock cmpthese);
my $hi = Hash::Inflator->new(path => '/path');
my $hao = Hash::AsObject->new(path => '/path');
my $dosd = Data::OpenStruct::Deep->new(path => '/path');
my $mock = Test::MockObject->new->set_always(path => '/path');
cmpthese(50000, {
hash_inflator_new => sub { Hash::Inflator->new(path => '/path') },
hash_asobject_new => sub { Hash::AsObject->new(path => '/path') },
data_openstruct_new => sub { Data::OpenStruct::Deep->new(path => '/path') },
test_mockobject_new => sub { Test::MockObject->new->set_always(path => '/path') },
});
cmpthese(300000, {
hash_inflator_get => sub { $hi->path },
hash_asobject_get => sub { $hao->path },
data_openstruct_get => sub { $dosd->path },
test_mockobject_get => sub { $mock->path },
});
cmpthese(50000, {
hash_inflator_new_get => sub { Hash::Inflator->new(path => '/path')->path },
hash_asobject_new_get => sub { Hash::AsObject->new(path => '/path')->path },
data_openstruct_new_get => sub { Data::OpenStruct::Deep->new(path => '/path')->path },
test_mockobject_new_get => sub { Test::MockObject->new->set_always(path => '/path')->path },
});
cmpthese(50000, {
hash_inflator_new_get2 => sub {
my $h = Hash::Inflator->new(path => '/path');
$h->path for 1..2;
},
hash_asobject_new_get2 => sub {
my $h = Hash::AsObject->new(path => '/path');
$h->path for 1..2;
},
data_openstruct_new_get2 => sub {
my $h = Data::OpenStruct::Deep->new(path => '/path');
$h->path for 1..2;
},
test_mockobject_new_get2 => sub {
my $h = Test::MockObject->new->set_always(path => '/path');
$h->path for 1..2;
},
});
cmpthese(50000, {
hash_inflator_new_get5 => sub {
my $h = Hash::Inflator->new(path => '/path');
$h->path for 1..5;
},
hash_asobject_new_get5 => sub {
my $h = Hash::AsObject->new(path => '/path');
$h->path for 1..5;
},
data_openstruct_new_get5 => sub {
my $h = Data::OpenStruct::Deep->new(path => '/path');
$h->path for 1..5;
},
test_mockobject_new_get5 => sub {
my $h = Test::MockObject->new->set_always(path => '/path');
$h->path for 1..5;
},
});
Rate test_mockobject_new data_openstruct_new hash_asobject_new hash_inflator_new
test_mockobject_new 18797/s -- -6% -61% -66%
data_openstruct_new 20000/s 6% -- -58% -64%
hash_asobject_new 48077/s 156% 140% -- -13%
hash_inflator_new 55556/s 196% 178% 16% --
Rate data_openstruct_get test_mockobject_get hash_inflator_get hash_asobject_get
data_openstruct_get 18680/s -- -16% -94% -97%
test_mockobject_get 22157/s 19% -- -93% -96%
hash_inflator_get 300000/s 1506% 1254% -- -49%
hash_asobject_get 588235/s 3049% 2555% 96% --
Rate data_openstruct_new_get test_mockobject_new_get hash_asobject_new_get hash_inflator_new_get
data_openstruct_new_get 9363/s -- -2% -76% -79%
test_mockobject_new_get 9542/s 2% -- -76% -79%
hash_asobject_new_get 39683/s 324% 316% -- -12%
hash_inflator_new_get 45045/s 381% 372% 14% --
Rate test_mockobject_new_get2 data_openstruct_new_get2 hash_asobject_new_get2 hash_inflator_new_get2
test_mockobject_new_get2 6452/s -- -5% -81% -81%
data_openstruct_new_get2 6821/s 6% -- -80% -80%
hash_asobject_new_get2 33333/s 417% 389% -- -3%
hash_inflator_new_get2 34247/s 431% 402% 3% --
Rate test_mockobject_new_get5 data_openstruct_new_get5 hash_inflator_new_get5 hash_asobject_new_get5
test_mockobject_new_get5 3394/s -- -6% -87% -88%
data_openstruct_new_get5 3605/s 6% -- -86% -88%
hash_inflator_new_get5 25641/s 655% 611% -- -11%
hash_asobject_new_get5 28902/s 751% 702% 13% --
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment