develooper Front page | perl.perl5.porters | Postings from February 2004

[PATCH] optimization for map in scalar context

Thread Next
Tassilo von Parseval
February 24, 2004 03:06
[PATCH] optimization for map in scalar context
Message ID:

the question whether map() has the same optimization for scalar context
as it has for void context was raised on clpm. It turned out that it
hasn't and the attached tiny and rather cheap patch puts things right.

The old behaviour was sub-optimal in that pp_mapwhile() made mortal
copies of the returned values in scalar-context. After weeding this out,
scalar-map performs a little better than void-map even (why, btw?):

         Rate   list   void scalar
list   4.74/s     --   -57%   -60%
void   11.1/s   134%     --    -6%
scalar 11.8/s   148%     6%     --

as opposed to

         Rate   list scalar   void
list   4.72/s     --   -33%   -57%
scalar 7.04/s    49%     --   -36%
void   11.0/s   133%    57%     --

for the three cases

    my @a = map $_+1, 1 .. 100000;
    my $a = map $_+1, 1 .. 100000;
    map $_+1, 1 .. 100000;
Since the values that are put onto the stack (as returned by map) are
meaningless in scalar-context, I used &PL_sv_undef for them. But
anything should do.


PS: I hope the whitespaces are in order this time.

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About