On Thu, Apr 13, 2000 at 04:59:07PM -0400, Jeff Pinyan wrote: > ---------- Forwarded message ---------- > From: Jeff Pinyan <jeffp@crusoe.net> > To: Bennett Todd <bet@rahul.net> > > >I only ever used map BLOCK LIST, never paid any attention to the > >alternative. Makes sense that EXPR, LIST would run faster. > > I wince slightly when I see constructs like > > @silly_way_to_unpack = map { ord } split //, $name; > > (Yes, poor example, since unpack("C*", $name) is much better.) > > I've done benchmarks that show that > > map ord, split //, $name; > > is faster. I don't see it. #!perl use Benchmark; $name = join '', 'a' .. 'z'; timethese(1 << shift, { expr => sub { @tmp1 = map ord, split //, $name; }, block => sub { @tmp2 = map { ord } split //, $name; }, } ); __END__ % perl bm.pl 11 Benchmark: timing 2048 iterations of block, expr... block: 1 wallclock secs ( 0.42 usr + 0.00 sys = 0.42 CPU) expr: 1 wallclock secs ( 0.55 usr + 0.00 sys = 0.55 CPU) % perl bm.pl 12 Benchmark: timing 4096 iterations of block, expr... block: 1 wallclock secs ( 0.96 usr + 0.01 sys = 0.97 CPU) expr: 2 wallclock secs ( 0.96 usr + 0.00 sys = 0.96 CPU) % perl bm.pl 13 Benchmark: timing 8192 iterations of block, expr... block: 3 wallclock secs ( 1.93 usr + 0.01 sys = 1.94 CPU) expr: 3 wallclock secs ( 1.79 usr + 0.01 sys = 1.80 CPU) % perl bm.pl 14 Benchmark: timing 16384 iterations of block, expr... block: 5 wallclock secs ( 3.72 usr + 0.01 sys = 3.73 CPU) expr: 5 wallclock secs ( 3.59 usr + 0.01 sys = 3.60 CPU) % perl bm.pl 15 Benchmark: timing 32768 iterations of block, expr... block: 11 wallclock secs ( 7.59 usr + 0.03 sys = 7.62 CPU) expr: 10 wallclock secs ( 7.66 usr + 0.02 sys = 7.68 CPU) % perl bm.pl 16 Benchmark: timing 65536 iterations of block, expr... block: 20 wallclock secs (15.30 usr + 0.05 sys = 15.35 CPU) expr: 20 wallclock secs (15.34 usr + 0.05 sys = 15.39 CPU) % And I don't think it would make sense for map EXPR, LIST to run faster than map { EXPR } LIST. Either way Perl just applies EXPR to each element of the list. Ronald ==== Want to unsubscribe from Fun With Perl? Well, if you insist... ==== Send email to <fwp-request@technofile.org> with message _body_ ==== unsubscribe