#!/usr/bin/perl -w use strict; use Benchmark; my %hash = ( DefaultLimit => 900, TimeLimit => 900, MODE => 'Off' ); sub by_hash { my $time_to_die; if ($hash{'TimeLimit'}) { if ($hash{'TimeLimit'} < $hash{'DefaultLimit'}) { $time_to_die = $hash{'TimeLimit'}; } else { $time_to_die = $hash{'DefaultLimit'}; } } else { $time_to_die = $hash{'DefaultLimit'}; } } sub by_var { my ($default, $time_to_die, $limit); $default = $hash{'DefaultLimit'}; $limit = $hash{'TimeLimit'} if ($hash{'TimeLimit'}); ($limit && ($limit < $default)) ? $time_to_die = $limit : $time_to_die = $default; } timethese (100000, { hash => 'by_hash', var => 'by_var'}); #### [13:20:12 jhorner@gateway lib]$ ./test1.pl Benchmark: timing 100000 iterations of hash, var... hash: 5 wallclock secs ( 4.57 usr + 0.00 sys = 4.57 CPU) @ 21881.84/s (n=100000) var: 4 wallclock secs ( 3.74 usr + 0.00 sys = 3.74 CPU) @ 26737.97/s (n=100000) [13:20:24 jhorner@gateway lib]$