Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Re: "switch$ia" (Russ: Useless Benchmarking again)

by echo (Pilgrim)
on Oct 10, 2001 at 21:19 UTC ( [id://118057]=note: print w/replies, xml ) Need Help??


in reply to Re: "switch$ia" (Russ: Useless Benchmarking again)
in thread "switch$ia" but don't interpolate trailing "a"

Someone please correct me if I'm wrong, ISTR interpolated strings are converted to concatenation at compile time?
  • Comment on Re: Re: "switch$ia" (Russ: Useless Benchmarking again)

Replies are listed 'Best First'.
Re: Re: Re: "switch$ia" (Russ: Useless Benchmarking again)
by Fletch (Bishop) on Oct 10, 2001 at 21:29 UTC

    You are correct, at least according to the B::Deparse documentation. Interpolation is just syntactic sugar for concatenation. You can see it for yourself:

    $ perl -MO=Deparse,-p,-q -e '$foo = "BAR"; $bar = "a${foo}c"; $baz="a" +.$foo."c"' ($foo = 'BAR'); ($bar = (('a' . $foo) . 'c')); ($baz = (('a' . $foo) . 'c'));

    Update: Added concatenation to the example for comparison. Also, the output using B::Terse to dump the opcode tree may be more convincing.

Re:(3) "switch$ia" (Russ: Really Useless Benchmarking)
by Russ (Deacon) on Oct 10, 2001 at 21:33 UTC
    <sheepish grin>
    hehehe You're probably right.

    So, in the spirit of further useless benchmarking:

    use Benchmark; timethese( 10000000, { 5 => sub {my $R = 5;}, 6 => sub {my $R = 6;} });
    results in:
    5: 6 wallclock secs ( 6.61 usr + -0.03 sys = 6.58 CPU) @ 1519756 +.84/s 6: 6 wallclock secs ( 5.89 usr + 0.08 sys = 5.97 CPU) @ 1675041 +.88/s
    As you can see, it is slightly faster to assign a 6 than a 5, so I will use 6's more often from now on... :-)
    </sheepish grin>

    Russ
    Brainbench 'Most Valuable Professional' for Perl

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-19 21:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found