in reply to Re: Re: Re: Generating an array of n identical elements
in thread Generating an array of n identical elements
Right. And using fixed values instead of generic subroutines appears to be much more (and more and more) fast:
#! perl -sw use strict; use Benchmark qw(cmpthese); my $mapgen = sub { return map 5, (1..1000); } ; my $xgen = sub { return (5) x 1000 ; } ; cmpthese( 10000, { mapgen => $mapgen, xgen => $xgen, }); __END__
gives, on my lightly-loaded Pentium IV 1.5Ghz,
Benchmark: timing 10000 iterations of mapgen, xgen... mapgen: 5 wallclock secs ( 5.04 usr + 0.03 sys = 5.07 CPU) @ 19 +72.39/s (n=10000) xgen: 0 wallclock secs ( 0.03 usr + 0.00 sys = 0.03 CPU) @ 33 +3333.33/s (n=10000) (warning: too few iterations for a reliable count) Rate mapgen xgen mapgen 1972/s -- -99% xgen 333333/s 16800% --
So map loses again. Uhm... it's the second time that other functions are far faster than map... I'd be interested in seeing a real case where map is the faster choice... does anyone have any?
Ciao!
--bronto
# Another Perl edition of a song:
# The End, by The Beatles
END {
$you->take($love) eq $you->made($love) ;
}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Generating an array of n identical elements
by Aristotle (Chancellor) on Sep 16, 2002 at 11:46 UTC | |
by bronto (Priest) on Sep 16, 2002 at 14:26 UTC |