Assembler programmers wouldn't program in Perl.

The mindset is indeed important. And it's very important to program in a language that fits ones mindset. If your mindset is that microseconds are important, Perl is the wrong language for you.

As for the actual differences:

#!/usr/bin/perl use strict; use warnings; use Benchmark 'cmpthese'; our @array = (1 .. 1000); foreach my $x (1 .. 10) { cmpthese -1, { alias => 'my $c = 0; foreach (@array) {$c += $_}', variable => 'my $d = 0; foreach my $var (@array) {$d += $var}' +, }; } __END__ Rate alias variable alias 3139/s -- -3% variable 3230/s 3% -- Rate alias variable alias 3139/s -- -2% variable 3199/s 2% -- Rate alias variable alias 3139/s -- -0% variable 3140/s 0% -- Rate alias variable alias 3140/s -- -0% variable 3143/s 0% -- Rate alias variable alias 3110/s -- -5% variable 3262/s 5% -- Rate alias variable alias 3083/s -- -5% variable 3229/s 5% -- Rate alias variable alias 3131/s -- -3% variable 3229/s 3% -- Rate alias variable alias 3083/s -- -5% variable 3229/s 5% -- Rate variable alias variable 2821/s -- -10% alias 3140/s 11% -- Rate alias variable alias 3140/s -- -2% variable 3200/s 2% --
You'd need to do some very careful analysis before deciding which of the two will save you some micro-seconds. Your analysis isn't based on anything. Just because something isn't in the code doesn't mean it isn't done.

In reply to Re^3: A question for the enlightened. by Anonymous Monk
in thread Using aliases in for loops or not? by jkva

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.