Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Benchmarks: Costs of OO Perl

by coreolyn (Parson)
on Jan 10, 2001 at 02:46 UTC ( [id://50798]=note: print w/replies, xml ) Need Help??


in reply to Dice::Die

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

Replies are listed 'Best First'.
Re: Benchmarks: Costs of OO Perl
by merlyn (Sage) on Jan 10, 2001 at 03:57 UTC
    I didn't scan all your article, but if you realize that most of the work of an object is not during dispatch, then your "20%" will become more like "2%" for non-trivial objects. I remember Damian saying this at a talk he gave last summer, and I think he'd know, having written the book on Perl Objects.

    -- Randal L. Schwartz, Perl hacker

      Whether or not most of the work of an object is during dispatch depends on how your have designed your system. In the example that led coreolyn to do those benchmarks the majority of the work actually was in creation of objects and dispatch to them. In a sample run I doubled the performance by doing direct hash access to attributes of objects rather than calling get methods.

      But yes, I think it is generally true that experienced OO programmers come up with designs where dispatch is not a major bottleneck.

        You may notice that the latest version makes use of the direct access. Is is Politically correct to access attributes directly if you are in that class? Is there a downside? I understand the hazards of direct access outside of a class but haven't considered internal direct access.

        coreolyn

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://50798]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-24 08:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found