With your benchmark, you are counting the overhead of calling subs in various ways. If you access a memory CELL directly (in machine language), that will be significantly faster than calling a function which computes the location of this CELL, and then accesses it. Same here. Subroutines have essentially the same performance penalty like method calls, since method calls
are just subs.
Calling subroutines means, in perl, not only that some code segment in memory is jumped to, but the build up of copious data structures by which the perl engine can keep track of context, and the tear-down of those stackframes after exiting. There is some optimization going on under the hood, as with subs declared with the NULL prototype returning a scalar and not relying on dynamic data or calling other subs, in which case their result will be inlined. But apart from that, calling subs just involves the overhead of, precisely - calling subs :-)
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.