This is an observation for the public record, more than it is a question. The speed of returning pointers to arrays in 5.10.0 is much faster than the speed of returning arrays:
#!/usr/bin/perl -w
use strict;
my $arraylength=1000;
sub return_arrays {
my @array;
for (my $i=0; $i<$arraylength; ++$i) { push(@array, rand()); }
return @array; ## or return \@array;
}
my $now=time();
my $sum=0;
for (my $j=0; $j<100_000; ++$j) {
my @v= return_arrays(); ## or my $v=
$sum+= $v[ rand($arraylength) ]; ## of $v->[
}
print "$sum\n";
print "Time: ".(time()-$now)." seconds\n";
on a Mac Pro, the array version takes 63 seconds. the reference version takes 22 seconds.
my guess is that perl actually copies the array on a return, rather than just move pointers around. this seems somewhat inefficient.
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.