Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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 :)

In reply to Benchmarks: Costs of OO Perl by coreolyn
in thread Dice::Die by coreolyn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-23 23:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found