• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Math.pow() issue

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Would like to know which process of the two stated below is faster
int x = y*1000
or
int x = y*Math.pow(10,3)
I'm using the second option as the value 3 is user-inputted parameter...Is there any way 2 get this done without any performance issues...
Well, do not have any performance-related issues with this, but may arise in the future...
TIA

MSM
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mahesh Mamani:
Well, do not have any performance-related issues with this, but may arise in the future...


1st Rule of Optimization: Don't.
2nd Rule of Optimization (for experts only): Don't... yet.
3rd Rule of Optimization: When you *really* need to, profile before optimizing - the bottleneck isn't where you think it is.
:roll:
See also http://c2.com/cgi/wiki?OptimizeLater
[ May 22, 2002: Message edited by: Ilja Preuss ]
 
Author
Posts: 6055
8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ilja Preuss:

1st Rule of Optimization: Don't.
2nd Rule of Optimization (for experts only): Don't... yet.
3rd Rule of Optimization: When you *really* need to, profile before optimizing - the bottleneck isn't where you think it is.
;)


Excellent, excellent advice! Well said. Mind if I quote you on that?
--Mark
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mark Herschberg:
Excellent, excellent advice! Well said. Mind if I quote you on that?


Oh, well - I stole it from http://c2.com/cgi/wiki?RulesOfOptimization, so I guess it would be ok...
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Now I'm going to (mostly) pretend this code has actually been established to be an issue...
Would like to know which process of the two stated below is faster
Uhhh, probably the one that uses a constant.
I'm using the second option as the value 3 is user-inputted parameter
Offhand, getting this parameter from the user - even if it's just read from a file - will probably take far longer than calulating an integer power of ten. Are you doing this in a loop or something? If not, who cares? If yes - will the user parameter change each time through the loop? If not - factor the calculation out of the loop. (Along with getting the user input in the first place.)
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic