http://qs321.pair.com?node_id=18161


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.