#!/usr/bin/perl use strict; use warnings; use Benchmark qw(:all); use Params::Validate qw(:all); sub ParamsValidateAssert { my ($test) = validate_pos( @_, { type => SCALAR, callbacks => { 'must be less than 50' => sub { $_[0] < 50 }}, } ); 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, { 'ParamsValidateAssert' => sub { eval { ParamsValidateAssert($_) } for (@nums) }, 'OrAssert' => sub { eval { OrAssert($_) } for (@nums) }, }); #### Benchmark: timing 10000 iterations of OrAssert, ParamsValidateAssert... OrAssert: 8 wallclock secs ( 7.02 usr + 0.01 sys = 7.03 CPU) @ 1422.48/s (n=10000) ParamsValidateAssert: 97 wallclock secs (87.88 usr + 0.38 sys = 88.26 CPU) @ 113.30/s (n=10000) Rate ParamsValidateAssert OrAssert ParamsValidateAssert 113/s -- -92% OrAssert 1422/s 1155% --