in reply to Re: Slow constants
in thread Slow constants
whereas the other two use AUTOLOAD to create the subs in their own package space and then &goto them...every time they are used.Eh, no. The first time they are used AUTOLOAD creates them and &gotos in them. The second time, the sub is there and the sub is called.
The difference is that Errno defines all the subs at compile time - they are empty prototyped subs returning a single value - and are hence are being constant folded at compile time. If you use EAGAIN, Perl will substitute the appropriate value at compile time - which avoids all the overhead of calling a subroutine at run time.
The benchmark is biased towards heavy use of constants. A typical program will only use a few constants, and only a few times in a program. That means that if you'd export a lot of constants the way Errno does, you pay a heavier price at compile time, regardless how often, and how many constants you use. Fcntl however avoids the costs of compiling all the subs you aren't going to use - but the price of using a constant goes up.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Slow constants
by BrowserUk (Patriarch) on Nov 02, 2005 at 17:03 UTC | |
by Perl Mouse (Chaplain) on Nov 02, 2005 at 17:22 UTC | |
|
Re^3: Slow constants
by powerman (Friar) on Nov 02, 2005 at 21:55 UTC |