Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

Compiler Optimization

Thread view: 
Luc The Perverse - 31 Dec 2005 20:36 GMT
Hello.    This is more a question of curiousity than actually needing a
performance increase.

I was wondering if the Java compiler (I am using Sun's j2sdk 1.4.2_10) will
change Math.PI * 2.0 into a constant in bytecode, or should I make a final
double above my function call?

Signature

LTP

:)
Stefan Ram - 31 Dec 2005 20:41 GMT
>I was wondering if the Java compiler (I am using Sun's j2sdk 1.4.2_10) will
>change Math.PI * 2.0 into a constant in bytecode, or should I make a final
>double above my function call?

 You can use

javap -c <classname>

 to see the bytecode.
NullBock - 31 Dec 2005 21:22 GMT
Equations solely consisting of compile-time constants are typically
solved before being compiled to byte code.  This is also true of
strings, so :

String s = "I want " + ((23 + 7) / 3) + " big macs";

would be stored in byte code as "I want 10 big macs".

Walter Gildersleeve
Freiburg, Germany

______________________________________________________
http://linkfrog.net
URL Shortening
Free and easy, small and green.
Luc The Perverse - 31 Dec 2005 23:11 GMT
> Equations solely consisting of compile-time constants are typically
> solved before being compiled to byte code.  This is also true of
[quoted text clipped - 3 lines]
>
> would be stored in byte code as "I want 10 big macs".

Oh that is even smarter than I thought :)

Alright cool thanks.

Signature

LTP

:)
Thomas Hawtin - 01 Jan 2006 17:20 GMT
> Hello.    This is more a question of curiousity than actually needing a
> performance increase.
>
> I was wondering if the Java compiler (I am using Sun's j2sdk 1.4.2_10) will
> change Math.PI * 2.0 into a constant in bytecode, or should I make a final
> double above my function call?

Should the value of PI change, then you will need to recompile your code.

Looking at the bytecode is not a particularly good way of determining
performance. The real optimisations happen at runtime, once your code
has been run 10,000 times. So when performance counts, benchmark your
actual code in a close to real life situation.

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.