![]() |
|
laziness, impatience, and hubris | |
PerlMonks |
cool off ... and let's do some benchmarksby inq123 (Sexton) |
on Mar 22, 2005 at 16:06 UTC ( #441519=note: print w/replies, xml ) | Need Help?? |
Hi, ZlR, First, cool off (I'm not trying to boss you around saying that). Even if the poster is an anonymous monk, the person's still trying to help, isn't it? Additionally, although you follow Larry Wall's camel book well, you forgot to follow the last suggestion in "User Efficiency" section, Chapter 24 (page 603 in 3rd version), right? Now back to business, let's do some benchmark:
Performance of eval - yeah, of course camel book's right, but it specifically said "avoid eval STRING inside a loop", yet you did not specify that's what you did in your post (and may I ask why you'd go against such suggestion in the first place?) But, any comment should be taken in context. eval is in fact faster than &$ calls, if you use block instead of STRING (and coding eval block is possible in your situtation. Not pretty, but for performance it's worth it). That's due to the overhead of subroutines. Then again, in real life situation where your subroutine does any amount of real work, such difference is negligible. Why? Simply take a look at this benchmark using this code:
Result: inq123@perlmonks$ perl test.pl inline 1 1000000 Method 'inline' took: 3 wallclock secs ( 2.86 usr + 0.00 sys = 2.86 CPU) inq123@perlmonks$ perl test.pl eval 1 1000000 Method 'eval' took: 3 wallclock secs ( 3.40 usr + 0.00 sys = 3.40 CPU) inq123@perlmonks$ perl test.pl sub 1 1000000 Method 'sub' took: 4 wallclock secs ( 3.57 usr + 0.00 sys = 3.57 CPU) inq123@perlmonks$ perl test.pl evalstr 1 1000000 Method 'evalstr' took:42 wallclock secs (41.25 usr + 0.00 sys = 41.25 CPU) inq123@perlmonks$ perl test.pl inline 10 100000 Method 'inline' took: 0 wallclock secs ( 0.47 usr + 0.00 sys = 0.47 CPU) inq123@perlmonks$ perl test.pl eval 10 100000 Method 'eval' took: 1 wallclock secs ( 0.53 usr + 0.00 sys = 0.53 CPU) inq123@perlmonks$ perl test.pl sub 10 100000 Method 'sub' took: 0 wallclock secs ( 0.55 usr + 0.00 sys = 0.55 CPU) inq123@perlmonks$ perl test.pl evalstr 10 100000 Method 'evalstr' took: 4 wallclock secs ( 4.30 usr + 0.00 sys = 4.30 CPU) inq123@perlmonks$ perl test.pl inline 100 10000 Method 'inline' took: 1 wallclock secs ( 0.25 usr + 0.00 sys = 0.25 CPU) inq123@perlmonks$ perl test.pl eval 100 10000 Method 'eval' took: 0 wallclock secs ( 0.24 usr + 0.00 sys = 0.24 CPU) inq123@perlmonks$ perl test.pl sub 100 10000 Method 'sub' took: 1 wallclock secs ( 0.25 usr + 0.00 sys = 0.25 CPU) inq123@perlmonks$ perl test.pl evalstr 100 10000 Method 'evalstr' took: 0 wallclock secs ( 0.62 usr + 0.00 sys = 0.62 CPU)It's clear that eval BLOCK is faster than &$, and both are much faster than putting eval STRING in a loop (again proving the wisdom of camel book :) ). That's why I said eval does not suffer significant performance penalty (except when you use it in a way that penalizes it). Now note that I'm just another guy trying to help out, so please don't flame me even if you don't like the post or the conclusion ... ;)
In Section
Seekers of Perl Wisdom
|
|