Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^3: A question for the enlightened.

by Anonymous Monk
on Feb 17, 2005 at 12:07 UTC ( #431900=note: print w/replies, xml ) Need Help??


in reply to Re^2: A question for the enlightened.
in thread Using aliases in for loops or not?

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.

Replies are listed 'Best First'.
Re^4: A question for the enlightened.
by fglock (Vicar) on Feb 17, 2005 at 12:31 UTC

    Assembler programmers wouldn't program in Perl.

    Yes they would :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://431900]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (9)
As of 2018-01-16 15:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How did you see in the new year?










    Results (182 votes). Check out past polls.

    Notices?