Chris Dolan via RT wrote:
Show quoted text> But eval q{use Foo}; is just a slow version of eval {require
> Foo;Foo->import};
>
> The latter has all of the runtime deferral of the former and adds
> compile-time syntax checking and avoids a runtime re-entrance into the
> compiler.
That's a good point. Benchmark[1] says it's about 5x faster that way. Of
course, we're talking 16000 iterations per second for the slow one, so
the chances of this mattering are zero. I think I'll stick with the
more readable version even if it is marginally slower.
--
see shy jo
joey@kodama:~>perl -e 'use Benchmark; use List::Util; timethese(100000, {stringy_eval => sub { eval q{use List::Util } } , optimised => sub { eval { require List::Util; List::Util->import } } })'
Benchmark: timing 100000 iterations of optimised, stringy_eval...
optimised: 1 wallclock secs ( 1.53 usr + 0.00 sys = 1.53 CPU) @ 65359.48/s (n=100000)
stringy_eval: 5 wallclock secs ( 6.11 usr + 0.00 sys = 6.11 CPU) @ 16366.61/s (n=100000)