Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: A question for the enlightened.

by jkva (Chaplain)
on Feb 17, 2005 at 10:23 UTC ( [id://431880]=note: print w/replies, xml ) Need Help??


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

Assembler programmers would spin in their graves generating electricity if they read this. Like I said in my previous post, it's the mindset that's important. Yes, they might me micro-secs, but micro-secs nonethless.

I do not see where I am using a nested forloop though. It's just a foreach.

-- Detonite

Replies are listed 'Best First'.
Re^3: A question for the enlightened.
by Anonymous Monk on Feb 17, 2005 at 12:07 UTC
    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.

      Assembler programmers wouldn't program in Perl.

      Yes they would :)

Re^3: A question for the enlightened.
by monkey_boy (Priest) on Feb 17, 2005 at 10:29 UTC
    Your not, but given that foreach is just an alias to for, what do you do with nested foreach loops!



    Im so sick of my Signature...
      I see what you mean, I did not know I could use a for instead of a foreach. I will look into this. Thanks.

      -- Detonite

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://431880]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2024-04-23 10:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found