#!/usr/bin/perl # # $Id: mod-vs-and 2592 2003-12-21 00:33:01Z jmates $ # # The author disclaims all copyrights and releases this document into # the public domain. # # Testing of mod versus bitwise and to determine even/odd. use Benchmark qw(cmpthese); $range = shift || 10; cmpthese(-5, { 'mod' => '$r = $_ % 2 for 1..$range', 'and' => '$r = $_ & 1 for 1..$range', }); # remove qw() bit and change 'cmpthese(-5' to 'timethese(10000' # if you have an older perl (pre 5.6?)