Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: Convert arithmetic expression from Excel to Perl syntax

by throttle (Beadle)
on Nov 04, 2004 at 18:03 UTC ( #405246=note: print w/replies, xml ) Need Help??


in reply to Re: Convert arithmetic expression from Excel to Perl syntax
in thread Convert arithmetic expression from Excel to Perl syntax

You can also di $temp**2 or $vol**2. Exactly the same, but faster.
  • Comment on Re^2: Convert arithmetic expression from Excel to Perl syntax

Replies are listed 'Best First'.
Re^3: Convert arithmetic expression from Excel to Perl syntax
by ikegami (Pope) on Nov 04, 2004 at 18:14 UTC
    You're right that ** works too, but you're wrong about it being faster (at least on my system).
    # srand(0) is used to make sure both # subs are using the same input set. sub m1 { unless ($i1) { srand(0); $i1=1; } $n = rand; $p = $n ** 2; } sub m2 { unless ($i2) { srand(0); $i2=1; } $n = rand; $p = $n * $n; } use Benchmark; Benchmark::cmpthese(0, { '$n**2' => \&m1, '$n*$n' => \&m2, }); __END__ Rate $n**2 $n*$n $n**2 722292/s -- -29% $n*$n 1013884/s 40% --
      when i said it was faster i meant that 'writing it' is faster

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2021-10-28 01:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (95 votes). Check out past polls.

    Notices?