Ah.. the cost/benifit ratio for perl 00
I think I've got an apples to apples here, hope someone will correct me if I'm wrong. I ran the benchmarks two different ways one with object creation in the benchmark and one with it outside. I put object creation outside of one of the benchmarks, as a way to statistically add a numerical factor for the convenience, reuse, and managament of OO over non-OO code.
Besides the lousy formating the results are pretty much what I expected, But I was suprised at the cost of just creating a stack for a simple subroutine, And, at where any benefits to the pseudo hash were.
It appears to me that if your willing to pay the cost for an OO die that you might as well pay the extra 20% to have the extra abilities one may desire. However the default behavior should be to NOT store values or have a 'face' unless required.
use Benchmark qw(cmpthese);
use strict;
use Dice::pureDieObj;
use Dice::di;
use Dice::diV02;
#my $pureDieObj = Dice::pureDieObj->get(20);
#my $FacelessDieObj = Dice::di->get(20,1);
#my $FacedDieObj = Dice::di->get(20);
#my $PsuedoHashDie = Dice::diV02->new( type=>20 );
system("clear");
my $loops;
for $loops (55000) {
cmpthese $loops, {
pureSub => sub {
my $roll = Die(20);
},
purists => sub {
my $roll = int( rand( 20 ) + 1 );
},
pureDieObj => sub { # No face/storage only a roll
my $pureDieObj = Dice::pureDieObj->get(20);
my $roll = $pureDieObj->roll;
},
FacelessDieObj => sub {
my $FacelessDieObj = Dice::di->get(20,1);
my $roll = $FacelessDieObj->roll;
},
FacedDieObjNotStored => sub {
my $FacedDieObj = Dice::di->get(20);
my $roll = $FacedDieObj->roll(1);
},
FacedDieObjStored => sub {
my $FacedDieObj = Dice::di->get(20);
my $roll = $FacedDieObj->roll;
},
PsuedoHashObj => sub {
my $PsuedoHashDie = Dice::diV02->new( type=>20 );
my $roll = $PsuedoHashDie->roll;
},
};
}
sub Die {
return int( rand( shift ) + 1 );
}
And the results...
With object creation:
Benchmark: timing 55000 iterations of FacedDieObjNotStored, FacedDieOb
+jStored, FacelessDieObj, PsuedoHashObj, pureDieObj, pureSub, purists.
+..
FacedDieObjNotStored: 6 wallclock secs ( 6.14 usr + 0.00 sys = 6.14
+ CPU) @ 8957.65/s (n=55000)
FacedDieObjStored: 7 wallclock secs ( 6.52 usr + 0.00 sys = 6.52 CP
+U) @ 8435.58/s (n=55000)
FacelessDieObj: 5 wallclock secs ( 5.58 usr + 0.00 sys = 5.58 CPU)
+@ 9856.63/s (n=55000)
PsuedoHashObj: 16 wallclock secs (15.08 usr + 0.00 sys = 15.08 CPU) @
+ 3647.21/s (n=55000)
pureDieObj: 5 wallclock secs ( 5.26 usr + 0.00 sys = 5.26 CPU) @ 10
+456.27/s (n=55000)
pureSub: 2 wallclock secs ( 1.09 usr + 0.00 sys = 1.09 CPU) @ 50
+458.72/s (n=55000)
purists: 1 wallclock secs ( 0.55 usr + 0.00 sys = 0.55 CPU) @ 10
+0000.00/s (n=55000)
Rate PsuedoHashObj FacedDieObjStored FacedDieObjNotStored FacelessDieO
+bj pureDieObj pureSub purists PsuedoHashObj 3647/s
+ -- -57% -59% -63% -65% -
+93% -96%
FacedDieObjStored 8436/s 131% --
+ -6% -14% -19% -83% -92%
FacedDieObjNotStored 8958/s 146% 6%
+ -- -9% -14% -82% -91%
FacelessDieObj 9857/s 170% 17%
+ 10% -- -6% -80% -90%
pureDieObj 10456/s 187% 24%
+ 17% 6% -- -79% -90%
pureSub 50459/s 1283% 498%
+ 463% 412% 383% -- -50%
purists 100000/s 2642% 1085%
+ 1016% 915% 856% 98% --
Without object creation factored in:
Benchmark: timing 55000 iterations of FacedDieObjNotStored, FacedDieOb
+jStored,
FacelessDieObj, PsuedoHashObj, pureDieObj, pureSub, purists...
FacedDieObjNotStored: 1 wallclock secs ( 2.32 usr + 0.00 sys = 2.32
+ CPU) @ 23706.90/s (n=55000)
FacedDieObjStored: 2 wallclock secs ( 2.77 usr + 0.00 sys = 2.77 CP
+U) @ 19855.60/s (n=55000)
FacelessDieObj: 1 wallclock secs ( 2.06 usr + 0.00 sys = 2.06 CPU)
+@ 26699.03/s (n=55000)
PsuedoHashObj: 3 wallclock secs ( 3.97 usr + 0.00 sys = 3.97 CPU) @
+ 13853.90/s (n=55000)
pureDieObj: 1 wallclock secs ( 1.72 usr + 0.00 sys = 1.72 CPU) @ 31
+976.74/s (n=55000)
pureSub: 2 wallclock secs ( 1.12 usr + 0.00 sys = 1.12 CPU) @ 49
+107.14/s (n=55000)
purists: 1 wallclock secs ( 0.51 usr + 0.00 sys = 0.51 CPU) @ 10
+7843.14/s (n=55000)
Rate PsuedoHashObj FacedDieObjStored FacedDieObjNotStored FacelessDieO
+bj pureDieObj pureSub purists PsuedoHashObj 13854/s
+ -- -30% -42% -48% -57%
+ -72% -87%
FacedDieObjStored 19856/s 43% --
+ -16% -26% -38% -60% -82%
FacedDieObjNotStored 23707/s 71% 19%
+ -- -11% -26% -52% -78%
FacelessDieObj 26699/s 93% 34%
+ 13% -- -17% -46% -75%
pureDieObj 31977/s 131% 61%
+ 35% 20% -- -35% -70%
pureSub 49107/s 254% 147%
+ 107% 84% 54% -- -54%
purists 107843/s 678% 443%
+ 355% 304% 237% 120% --
Of course I'm sure the purist are looking at the numbers wondering why anyone would even consider a Die object. But I still contend that for an ease of application development and management in large dice intensive applications, or just for ease of use in small ones it's worth the associated costs. Besides it is proving to be a great study in OO and Perl.
coreolyn - Still waiting for hardware and software to catch up to my vision :) |