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.
In reply to Re^2: Slow constants
by Perl Mouse
in thread Slow constants
by powerman
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |