| Next | Making Programs Faster | 94 |
>> Would this improve performance?
>
> Write a benchmark and see.
Well alright :-)
#!/usr/bin/perl -w
#test.pl
use strict;
use Benchmark;
undef $/;
my $code;
timethese(8000, {
'Slow Eval' => sub {open(INPUT, 'code.pl');$code =
<INPUT>;close(INPUT);eval $code;},
'Fast Eval' => sub {open(INPUT, 'code.pl');$code =
<INPUT>;close(INPUT);eval {$code;};}
});
Results:
Benchmark: timing 8000 iterations of Fast Eval, Slow Eval...
Fast Eval: 0 wallclock secs
( 0.30 usr + 0.13 sys = 0.43 CPU)
Slow Eval: 6 wallclock secs
( 4.98 usr + 0.42 sys = 5.40 CPU)
So apparently an eval block is significantly faster than
calling eval() on a scalar.
Well, that's good to know
Anyone see the problem here?
| Next | ![]() |
Copyright © 2003 M. J. Dominus |