Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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?

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (2)
As of 2022-01-19 05:43 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (55 votes). Check out past polls.