On Sun, Nov 03, 2002 at 11:48:55AM -0600, Steven Lembark wrote:
> >I'm not sure anyone has actually posited using map for performance, but
> >in most cases that would indeed be a pretty stupid reason to use it.
> See the Schwartzian Transform for an excellent example of
> where you would use map for performance. 

We're drifting further and further off topic here, but the trick to the 
Schwartzian Transform is the caching, not the maps. The maps are just a
convenient construct that allows the whole thing to be written in one
command, without lots of temporary variables. 

In terms of speed, the difference between

  my @sorted = 
    map  { $_->[0] } 
    sort { $a->[1] <=> $b->[1] } 
    map  { [$_, -M $_] } @files;

and

  my @cache; push @cache, [$_, -M $_] foreach @files;
  my @sorted_cache = sort { $a->[1] <=> $b->[1] } @cache;
  my @sorted; push @sorted, $_->[0] foreach @sorted_cache;

is quite neglible compared with the speed difference of doing

  my @sorted = sort { -M $a <=> -M $b } @files

especially as the cost of the operation (-M in this case) increases.


Tony


Reply via email to