use Benchmark qw( cmpthese ) ;
my $wait = -34;
cmpthese( -2, {
a=>sub{
$wait = $wait < 0 ? 0 : $wait ;
$wait = -34;
},
b=>sub{
if ($wait < 0 ){ $wait = 0};
$wait = -34;
},
c=>sub{
$wait = 0 unless $wait > 0;
$wait = -34;
},
d=>sub{
$wait = 0 unless abs($wait);
$wait = -34;
},
####
Rate a b c d
a 4216652/s -- -16% -17% -36%
b 5010637/s 19% -- -2% -24%
c 5094673/s 21% 2% -- -23%
d 6616606/s 57% 32% 30% --
####
Rate a b c d
a 3542992/s -- -5% -6% -50%
b 3742730/s 6% -- -1% -47%
c 3766874/s 6% 1% -- -47%
d 7084993/s 100% 89% 88% --