Well, taking nothing for granted (note, I did try larger arrays, fewer iterations, etc
, and still got similar results):
use Benchmark;
my @arr=(0..10000);
open(FH1, '>file1') or die "file1: $!";
open(FH2, '>file2') or die "file2: $!";
open(FH3, '>file3') or die "file3: $!";
timethese(100, {
BIGJOIN=>\&bigjoin,
ITERATE=>\&iterate,
MAPIT=>\&mapit,
});
close FH1;
close FH2;
close FH3;
sub bigjoin {
print FH1 join("\n", @arr, '');
}
sub iterate {
print FH2 "$_\n" for @arr;
}
sub mapit {
print FH3 map "$_\n" @arr;
}
>perl tst
Benchmark: timing 100 iterations of BIGJOIN, ITERATE, MAPIT...
BIGJOIN: 3 wallclock secs ( 3.41 usr + 0.00 sys = 3.41 CPU) @ 29
+.33/s (n=100)
ITERATE: 14 wallclock secs (13.57 usr + 0.00 sys = 13.57 CPU) @ 7
+.37/s (n=100)
MAPIT: 17 wallclock secs (16.86 usr + 0.00 sys = 16.86 CPU) @ 5
+.93/s (n=100)
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.