#!/usr/bin/perl
use strict;
use Benchmark qw(:all);
cmpthese(10, {
'eq' => sub {
for (my ($i, $j) = (0, 0); $i < 1_000_000; $i++) {
$j++ if ($i % 3) eq 2;
}
},
'==' => sub {
for (my ($i, $j) = (0, 0); $i < 1_000_000; $i++) {
$j++ if ($i % 3) == 2;
}
},
});
__END__
Benchmark: timing 10 iterations of ==, eq...
==: 28 wallclock secs (27.91 usr + 0.00 sys = 27.91 CPU) @ 0
+.36/s (n=10)
eq: 36 wallclock secs (36.16 usr + 0.01 sys = 36.17 CPU) @ 0
+.28/s (n=10)
s/iter eq ==
eq 3.62 -- -23%
== 2.79 30% --
The test was run on my Powerbook G3 with Perl v5.8.0 built for powerpc-linux-thread-multi.
I agree we shouldn't program for speed only, but here speed and good form comes from the same expression. Also you may note how my first post in this thread started out with "Also": it wasn't meant to be a comprehensive response to c's problem, but instead my 2 cents to what already said.
$|=$_="1g2i1u1l2i4e2n0k",map{print"\7",chop;select$,,$,,$,,$_/7}m{..}g
|