----- Original Message ----- From: "Glenn Linderman" . . > > Get a load of this variation: > > perl > use warnings; > no warnings "once"; > use Benchmark; > > @x = (1 .. 1000000); > @y = (1 .. 1000000); > @z = (1 .. 1000000); > @w = (1 .. 1000000); > > $z1 = 0; > $z2 = 0; > $z3 = 0; > $z4 = 0; > > timethese(10, { > 'forgrep' => 'for(grep($_ != 3, @w)){ $z4++ }', > 'next' => 'for(@z) {next if $_ == 3; $z3++}', > 'brackets' => 'for(@y) {if($_ != 3){$z2++}}', > 'modifier' => 'for(@x) {$z1++ if $_ != 3}', > }); > > print "\n", $z1, " ", $z2, " ", $z3, " ", $z4, "\n"; > __END__ > > Benchmark: timing 10 iterations of brackets, forgrep, modifier, next... > brackets: 4 wallclock secs ( 3.73 usr + 0.00 sys = 3.73 CPU) @ > 2.68/s (n=10) > forgrep: 3 wallclock secs ( 3.19 usr + 0.00 sys = 3.19 CPU) @ > 3.14/s (n=10) > modifier: 3 wallclock secs ( 2.61 usr + 0.00 sys = 2.61 CPU) @ > 3.83/s (n=10) > next: 3 wallclock secs ( 2.64 usr + 0.00 sys = 2.64 CPU) @ > 3.79/s (n=10) > > 9999990 9999990 9999990 9999990 >
Yeah .... beats me how 'forgrep' could be faster than 'brackets'. I had also done some timings on use of 'next' and found it to be inexplicably fast. IIRC, there is very little difference (timewise) between "next if $_ == 3;" and "if($_ == 3) {next}". At one stage I got the impression that $_==3 could be evaluated more quickly than $_!=3, but I don't know if that's so. Anyway ..... I probably wouldn't understand it even if it was explained to me :-) Cheers, Rob _______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs