Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2024-04-26 07:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found