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.


In reply to Re: $r-dir_config and speed by plaid
in thread $r-dir_config and speed by jjhorner

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.