in reply to Re^4: Avoiding Globals with OO Perl
in thread Avoiding Globals with OO Perl
Look again and re-assess. There is no exaggeration.
Both tests set and reference the variable 1000 times each. The reason for including a loop inside the both benchmark subs is to amortise the cost of that subroutine call across the 1000 iterations of the code under test. Without it, the code would be benchmarking the calling of the benchmark sub, not the code under test.
If the benchmark is not to your taste, then consider this. Setting and then referencing a single scalar value involves:
And finally one each of setting or reading the value of the actual scalar.
All in all, it is quite remarkable that the pointless OO code is only 7 1/2 times slower.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Avoiding Globals with OO Perl
by chromatic (Archbishop) on Oct 21, 2011 at 01:35 UTC | |
by BrowserUk (Patriarch) on Oct 21, 2011 at 02:25 UTC | |
by chb (Deacon) on Oct 21, 2011 at 08:32 UTC |