You are being unfair to map.

#!/usr/bin/perl -w use Benchmark; use strict; my $count = shift || -3 ; # set the test counter my @array; #load up an array of crap push @array, rand(256) for 1 .. 1000; open NULL, ">/dev/null" or die $!; timethese ( $count, { 'join' => \&print_join, 'map' => \&print_map, 'list map' => \&print_map_list, 'field sep' => \&print_field, 'for' => \&print_for } ); # use join to print each array elemnet. sub print_join { print NULL join("\n", @array); } # use map to print each array elemnt, sub print_map { print NULL map{ $_ .= "\n"} @array; } # same but a no concat sub print_map_list { print NULL map { ($_, "\n") } @array; } # use map to print each array elemnt, sub print_field { local $, = "\n"; print NULL @array; } # use a loop. sub print_for { print NULL $_, "\n" for @array; }
Yields:
Benchmark: running field sep, for, join, list map, map, each for at least 9 CPU seconds...
 field sep: 11 wallclock secs ( 9.60 usr +  0.05 sys =  9.65 CPU) @ 1121.04/s (n=10818)

       for: 11 wallclock secs ( 9.28 usr +  0.02 sys =  9.30 CPU) @ 621.40/s (n=5779)
      join: 11 wallclock secs ( 9.20 usr +  0.02 sys =  9.22 CPU) @ 2888.07/s (n=26628)
  list map: 11 wallclock secs ( 9.07 usr +  0.04 sys =  9.11 CPU) @ 268.94/s (n=2450)
       map: 32 wallclock secs (26.02 usr +  0.26 sys = 26.28 CPU) @ 57.95/s (n=1523)
What happened with your field sep test? I can't get it as fast as you claim it to be. You should also note that join does not put a newline after the final item.

- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.


In reply to Re: Re: Request for further enlightenment by Juerd
in thread Request for further enlightenment by BrowserUk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.