#!/usr/bin/perl use strict; use warnings; use Benchmark qw(:all); use Carp::Assert; sub CarpAssert { my ($test) = @_; assert($test < 50) if DEBUG; return $test; } sub OrAssert { my ($test) = @_; ($test < 50) || die "Test is wrong"; return $test; } my @nums = map { ((rand() * 100) % 50) } (0 .. 100); cmpthese(10_000, { 'CarpAssert' => sub { eval { CarpAssert($_) } for (@nums) }, 'OrAssert' => sub { eval { OrAssert($_) } for (@nums) }, }); #### Benchmark: timing 10000 iterations of CarpAssert, OrAssert... CarpAssert: 11 wallclock secs ( 9.92 usr + 0.04 sys = 9.96 CPU) @ 1004.02/s (n=10000) OrAssert: 8 wallclock secs ( 7.14 usr + 0.03 sys = 7.17 CPU) @ 1394.70/s (n=10000) Rate CarpAssert OrAssert CarpAssert 1004/s -- -28% OrAssert 1395/s 39% -- #### Benchmark: timing 10000 iterations of CarpAssert, OrAssert... CarpAssert: 9 wallclock secs ( 6.50 usr + 0.03 sys = 6.53 CPU) @ 1531.39/s (n=10000) OrAssert: 10 wallclock secs ( 6.72 usr + 0.02 sys = 6.74 CPU) @ 1483.68/s (n=10000) Rate OrAssert CarpAssert OrAssert 1484/s -- -3% CarpAssert 1531/s 3% -- #### sub noOpError {} sub OrAssert { my ($test) = @_; ($test < 50) || noOpError("Test is wrong"); return $test; } #### Benchmark: timing 10000 iterations of CarpAssert, OrAssert... CarpAssert: 6 wallclock secs ( 6.54 usr + 0.00 sys = 6.54 CPU) @ 1529.05/s (n=10000) OrAssert: 7 wallclock secs ( 7.11 usr + 0.02 sys = 7.13 CPU) @ 1402.52/s (n=10000) Rate OrAssert CarpAssert OrAssert 1403/s -- -8% CarpAssert 1529/s 9% --