Of course, the biggest flaw is the use the Benchmark module itself. How can use trust a module that sometimes reports negative times?
#!/usr/bin/perl use strict; use warnings; use Time::HiRes 'gettimeofday'; my $ITERATIONS = 10_000_000; my $counter1 = 0; my $counter2 = 0; my ($s1, $m1) = gettimeofday; for (1 .. $ITERATIONS) {$a = ++$counter1 & 1} my ($s2, $m2) = gettimeofday; for (1 .. $ITERATIONS) {$a = ++$counter2 % 2} my ($s3, $m3) = gettimeofday; my $d1 = $s2 - $s1 + ($m2 - $m1) / 1_000_000; my $d2 = $s3 - $s2 + ($m3 - $m2) / 1_000_000; printf "And: %.6f Mod: %.6f\n", $d1, $d2; __END__ And: 2.954181 Mod: 3.093696 And: 3.320696 Mod: 3.321606 And: 3.096083 Mod: 3.218991 And: 2.977993 Mod: 3.113543 And: 2.954634 Mod: 3.100933 And: 2.836724 Mod: 3.168724 And: 2.880770 Mod: 3.472917 And: 3.117684 Mod: 3.552177 And: 3.668317 Mod: 3.616199 And: 3.126708 Mod: 3.126385
In reply to Re^2: &1 is no faster than %2 when checking for oddness. (Careful what you benchmark)
by Anonymous Monk
in thread &1 is no faster than %2 when checking for oddness. Oh well.
by diotalevi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |