I dont think you tested these ideas very hard. They are solid gold for procedural languages that are close to the metal, but for perl they are misplaced.

I benchmarked your routines (which are inequivalent, btw) against tilly's map. Output is:

Benchmark: timing 1000 iterations of dimmesdale PU, dimmesdale loop, p +erlish... dimmesdale PU: 36 wallclock secs (34.87 usr + 0.09 sys = 34.96 CPU) dimmesdale loop: 43 wallclock secs (40.63 usr + 0.13 sys = 40.76 CPU) perlish: 35 wallclock secs (33.47 usr + 0.10 sys = 33.57 CPU)

where "dimmesdale loop" and "perlish" are equivalent, and "dimmesdale PU" does init in identical blocks of 10. Benchmark code appended.

After Compline,
Zaxo

#!/usr/bin/perl -w # -*-Perl-*- use Benchmark; my @ary; sub init_val {$_[0]} sub dimmeloop { for($i = 0; $i <= 10_000; $i++) { $ary[$i] = init_val($i); } 1; } sub dimmeunroll { $idx = 0; for($i = 0; $i < 10_000; $i += 10) { $ary[$idx++] = init_val($i); $ary[$idx++] = init_val($i); $ary[$idx++] = init_val($i); $ary[$idx++] = init_val($i); $ary[$idx++] = init_val($i); $ary[$idx++] = init_val($i); $ary[$idx++] = init_val($i); $ary[$idx++] = init_val($i); $ary[$idx++] = init_val($i); $ary[$idx++] = init_val($i); } 1; } sub tillys { @ary = map {init_val $_} (0..10000); 1; } timethese(1000,{ 'dimmesdale loop'=>"dimmeloop", 'dimmesdale PU'=>"dimmeunroll", 'perlish'=>"tillys", });

In reply to Re: Optimizations and Efficiency by Zaxo
in thread Optimizations and Efficiency by dimmesdale

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.