Hello
WikiGuest
Log In
or
Register
Users
About
Blog
Extensions
Documentation
Community
Development
Tasks
Download
Support
You are here:
Foswiki
>
Development Web
>
ToOOOrNotToOO
(revision 3) (raw view)
To Object Orient or not to Object Orient, that is the question.%BR% Whether 'tis nobler of mind to suffer the subs and gotos of outrageous C,%BR% Or to use Classes against a sea of spaghetti. (apologies to Shakespear) Try this: <verbatim> # Compare OO construction against non-OO. # $0 oo will run the OO version # $0 bless will run the blessing version # $0 with no params the non-OO use strict; use Benchmark ':hireswallclock'; { package ObjectAddress; sub new { my ($class, %opts) = @_; return bless(\%opts, $class); }; } my $make; my $what; if (scalar(@ARGV) && $ARGV[0] eq 'oo') { $what = "OO"; $make = sub { my $i = shift; return ObjectAddress->new( webs => ['rootweb', 'web', 'subweb', 'subsubweb'], topic => 'Topic', rev => 123, attachment => 'filename', i => $i); } } elsif (scalar(@ARGV) && $ARGV[0] eq 'bless') { $what = "Bless"; $make = sub { my $i = shift; return bless({ webs => ['rootweb', 'web', 'subweb', 'subsubweb'], topic => 'Topic', rev => 123, attachment => 'filename', i => $i },"ObjectAddress") } } else { $what = "No OO"; $make = sub { my $i = shift; return { webs => ['rootweb', 'web', 'subweb', 'subsubweb'], topic => 'Topic', rev => 123, attachment => 'filename', i => $i } } }; my $t0 = Benchmark->new(); my @objects; for my $i (1..100000) { $objects[$i] = &$make(); } my $t1 = Benchmark->new; my $td = timediff($t1, $t0); print "$what took:",timestr($td),"\n"; </verbatim> -- Main.CrawfordCurrie - 09 Feb 2011 Running this gives me very different results each time, dependent on other processes on the machine. But overall it looks like OO costs about 10% to 20% overhead. -- Main.ArthurClemens - 09 Feb 2011
BasicForm
edit
TopicClassification
Select one...
TopicSummary
InterestedParties
E
dit
|
A
ttach
|
P
rint version
|
H
istory
: r3
<
r2
<
r1
|
B
acklinks
|
V
iew topic
|
Edit
w
iki text
|
M
ore topic actions
Topic revision: r3 - 09 Feb 2011,
CrawfordCurrie
Development
Quick Links
Tasks and Bugs
Developers Bible
Release Plan
Feature Proposals
Topic Classification
Tools
Tasks
Index
Changes
Changes in all webs
Notifications
Statistics
Sandbox
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. see
CopyrightStatement
.