* Rick Delaney (rick.delaney@home.com) [991001 00:00]: > Uri Guttman wrote: > > > > well it helps to compare apples to macintoshes! a proper foreach > > statement is a very different animal than a foreach statement modifier. > > > > so your benchmarks are moot. map and foreach modifiers are know be be of > > similar speed and both are generally faster than foreach statements. > > Well, now the burden of proof has shifted to you. Feel free to modify > the benchmark to prove this. Or offer up some other proof. I'm surpised that you don't think Uri deserves the same slack as Larry. I can tell you, they have both done WAY more than their fair share of benchmarks. Anyway, here's mine. (N=1000) Benchmark: timing 1000 iterations of foreach-normal, foreach-modifier, map, map-opt1... foreach-normal: 25 wallclock secs (24.75 usr + 0.00 sys = 24.75 CPU) foreach-modifier: 31 wallclock secs (25.21 usr + 0.01 sys = 25.22 CPU) map: 36 wallclock secs (30.05 usr + 0.02 sys = 30.07 CPU) map-opt1: 30 wallclock secs (28.53 usr + 0.02 sys = 28.55 CPU) I draw 3 conclusions: 1. the normal foreach is NOT significantly slower than the foreach modifier, contrary to another recent claim. 2. foreach is consistently faster than map. 3. making one array for the keys gives some improvement over having two lists. use Benchmark; my $iterations =shift or die "Usage: $0 n_iterations\n"; my $array_size = int( 1_000_000 / $iterations ); my %sites; while ( keys %sites < $array_size ) { $sites{ int( rand( 10_000_000 ) ) } = 1; } sub mindshare { rand 1 } timethese( $iterations, { 'foreach-normal' => sub { my %shares; for ( keys %sites ) { $shares{$_} = mindshare($_); } }, 'foreach-modifier' => sub { my %shares; $shares{$_} = mindshare($_) for keys %sites; }, 'map' => sub { my %shares; @shares{keys %sites} = map { mindshare($_) } keys %sites; }, 'map-opt1' => sub { my %shares; my @k = keys %sites; @shares{@k} = map { mindshare($_) } @k; }, }); % perl -V Summary of my perl5 (revision 5.0 version 5 subversion 60) configuration: Platform: osname=solaris, osvers=2.6, archname=sun4-solaris uname='sunos hla16 5.6 generic_105181-10 sun4u sparc sunw,ultra-2 ' config_args='' hint=previous, useposix=true, d_sigaction=define usethreads=undef useperlio=undef d_sfio=undef use64bits=undef usemultiplicity=undef Compiler: cc='cc', optimize='-O', gccversion= cppflags='-DDEBUGGING' ccflags ='-DDEBUGGING' stdchar='unsigned char', d_stdstdio=define, usevfork=false intsize=4, longsize=4, ptrsize=4, doublesize=8 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16 alignbytes=8, usemymalloc=y, prototype=define Linker and Libraries: ld='cc', ldflags =' -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib /usr/ccs/lib libs=-lsocket -lnsl -ldl -lm -lc -lcrypt -lsec libc=/lib/libc.so, so=so, useshrplib=false, libperl=libperl.a Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' ' cccdlflags='-KPIC', lddlflags='-G -L/usr/local/lib' Characteristics of this binary (from libperl): Compile-time options: DEBUGGING Built under solaris -- John Porter ==== Want to unsubscribe from Fun With Perl? Well, if you insist... ==== Send email to <fwp-request@technofile.org> with message _body_ ==== unsubscribe