Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Re: Idiomatic optimizations

by belg4mit (Prior)
on May 01, 2002 at 03:50 UTC ( #163209=note: print w/ replies, xml ) Need Help??


in reply to Re: Idiomatic optimizations
in thread Idiomatic optimizations

With 5.6.1...

On an otherwise unloaded P4 1.g GHz

1 Rate single double 2 Rate single double single 4219409/s -- -7% single 4273504/s -- -18% double 4524887/s 7% -- double 5208333/s 22% -- 3 Rate single double 4 Rate single double single 4201681/s -- -8% single 4166667/s -- -22% double 4566210/s 9% -- double 5347594/s 28% --

On an otherwise reasonably loaded (0.31) sun4u

1 Rate double single 2 Rate double single double 3079766/s -- -18% double 3054368/s -- -11% single 3763643/s 22% -- single 3419973/s 12% -- 3 Rate double single 4 Rate double single double 2866972/s -- -18% double 3107520/s -- -10% single 3495281/s 22% -- single 3437607/s 11% --

--
perl -pew "s/\b;([mnst])/'$1/g"


Comment on Re: Re: Idiomatic optimizations
Select or Download Code
Re: Re: Re: Idiomatic optimizations
by Juerd (Abbot) on May 01, 2002 at 16:52 UTC

    On an otherwise unloaded P4 1.g GHz

    For certain very specific meanings of the word "unloaded", I'm sure. "foo" is optimized to 'foo' at compile time, so neither of them can possibly be faster. As you can see, the generated bytecode is equivalent:

    2;0 juerd@ouranos:~$ perl -MO=Concise -e'$foo = "foo"' 6 <@> leave[t1] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 1 -e:1) v ->3 5 <2> sassign vKS/2 ->6 3 <$> const(PV "foo") s ->4 - <1> ex-rv2sv sKRM*/1 ->5 4 <$> gvsv(*foo) s ->5 -e syntax OK 2;0 juerd@ouranos:~$ perl -MO=Concise -e'$foo = '\''bar'\' 6 <@> leave[t1] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 1 -e:1) v ->3 5 <2> sassign vKS/2 ->6 3 <$> const(PV "bar") s ->4 - <1> ex-rv2sv sKRM*/1 ->5 4 <$> gvsv(*foo) s ->5 -e syntax OK
    Even "Hello, $name!" is optimized to 'Hello, ' . $name . '!'.

    Note: I _do_ think people should use single quotes when not interpolating. It saves you a lot of hits on the backslash key, and avoids getting bitten by: "$You're kidding me" (eq. "$You::re kidding me"), "my@emailaddress.com" (intended: "my\@emailaddress.com").

    - Yes, I reinvent wheels.
    - Spam: Visit eurotraQ.
    

      >For certain very specific meanings of the word "unloaded"
      Yes of course, namely 0.0 (!) And we've already established that the bytecode is *supposedly* the same, afterall is it not true that Deparse is not guaranteed to reconstruct things exactly? So this adds nothing new. It does not help describe the erratic behavior.

      --
      perl -pew "s/\b;([mnst])/'$1/g"

        afterall is it not true that Deparse is not guaranteed to reconstruct things exactly

        It is true that Deparse is not guaranteed to reconstruct things exactly. That's why I did use B::Concise, not B::Deparse. It prints the generated bytecode in a semi-readable way, it does not re-construct Perl code.

        The bytecode isn't "supposedly" the same, it IS the same. You could use B::Bytecode to get the raw bytecode (Can't paste because of its binary format), and you could use diff to check their being equivalent. Only compile-time can differ with single/double quotes, so had you benchmarked eval q/$foo = 'foo'/ versus eval q/$foo = "foo"/, you could have gotten some difference. Run-time can, as far as I can see with all the nice tools that let you dig into the generated bytecode, not be different for "foo" versus 'foo', unless when they're evaluated in different circumstances. A load of 0.00 does not mean your system is doing absolutely nothing, as the number is the _average_ number of instructions waiting in a _queue_. If your system is capable of handling simple instructions immediately, you can have a somewhat loaded system with a 0.00 "load average" number.

        This indeed does not give any information as to why you got these strange - and as far as I can test impossible - results, but as all my tests (and not only mine) on different systems tell me that "foo" versus 'foo' is a tie, I think you shouldn't trust your benchmark results. Have you been benchmarking using eval STRING, or anything else that makes difference on run-time?

        - Yes, I reinvent wheels.
        - Spam: Visit eurotraQ.
        

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (8)
As of 2014-08-21 05:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (127 votes), past polls