Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: $r-dir_config and speed

by plaid (Chaplain)
on Jun 14, 2000 at 23:21 UTC ( #18161=note: print w/replies, xml ) Need Help??


in reply to $r-dir_config and speed

First, a minor stylistic issue; the line
($limit < $default) ? $time_to_die = $limit : $time_to_die = $default;
Is more often written
$time_to_die = ($limit < $default) ? $limit : $default;
But back to the matter at hand. In general, any value that has to be looked up in a hash or through a function is going to be slower than just grabbing a scalar. A quick benchmark I wrote:
package Apache::Test; use strict; use Apache::Constants qw(:common); use Benchmark; use vars qw($r); # Not a good idea in general, but I couldn't # figure out how to pass parameters in a # benchmark. Works fine for benchmarking purposes. sub handler { $r = shift; $r->send_http_header; $r->print("by_dirconfig:",timestr(timeit(250000,\&by_dirconfig +)),"\n"); $r->print("by_var:", timestr(timeit(250000, \&by_var)), "\n"); return OK; } sub by_dirconfig { my $time_to_die; if ($r->dir_config('TimeLimit')) { if ($r->dir_config('TimeLimit') < $r->dir_config('Defa +ultLimit')) { $time_to_die = $r->dir_config('TimeLimit'); } else { $time_to_die = $r->dir_config('DefaultLimit'); } } else { $time_to_die = $r->dir_config('DefaultLimit'); } } sub by_var { my ($default, $time_to_die, $limit); $default = $r->dir_config('DefaultLimit'); $limit = $r->dir_config('TimeLimit') if ($r->dir_config('TimeL +imit')); $time_to_die = ($limit < $default) ? $limit : $default; } 1;
Which leaves in my browser window:

by_dirconfig:14 wallclock secs (15.28 usr + 0.03 sys = 15.31 CPU)
by_var:11 wallclock secs (12.07 usr + 0.02 sys = 12.09 CPU)

Conclusions are about the same as yours, just thought I'd add my results.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://18161]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2020-05-27 00:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (152 votes). Check out past polls.

    Notices?