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 ); } #### Benchmark: timing 55000 iterations of FacedDieObjNotStored, FacedDieObjStored, 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 CPU) @ 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) @ 10456.27/s (n=55000) pureSub: 2 wallclock secs ( 1.09 usr + 0.00 sys = 1.09 CPU) @ 50458.72/s (n=55000) purists: 1 wallclock secs ( 0.55 usr + 0.00 sys = 0.55 CPU) @ 100000.00/s (n=55000) Rate PsuedoHashObj FacedDieObjStored FacedDieObjNotStored FacelessDieObj 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% -- #### Benchmark: timing 55000 iterations of FacedDieObjNotStored, FacedDieObjStored, 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 CPU) @ 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) @ 31976.74/s (n=55000) pureSub: 2 wallclock secs ( 1.12 usr + 0.00 sys = 1.12 CPU) @ 49107.14/s (n=55000) purists: 1 wallclock secs ( 0.51 usr + 0.00 sys = 0.51 CPU) @ 107843.14/s (n=55000) Rate PsuedoHashObj FacedDieObjStored FacedDieObjNotStored FacelessDieObj 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% --