This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I do not think that you are comparing static variables with local variables. You are comparing inline integer literals (e.g. 10) with constants (static final int B10 = 10 ; ) .
I am surprised that there is a big difference in performance, as I would have thought that the hotspot compiler would manage to inline the constants. [ October 14, 2004: Message edited by: Peter Chase ]
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Originally posted by Peter Chase: I would have thought that the hotspot compiler would manage to inline the constants.
I think it might even already be inlined at compile time.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
I tried the same examples several times and ended up with no visible difference in time execution when running both the examples. I am running v1.4.2_04
Joined: Sep 29, 2000
The performance difference that you see is probably because it takes longer to execute a program using the JRE initially. There may be stuff going on behind the scenes the first time you access the JRE while your program is running. I would try running both the programs several times one right after each other to get a more accurate picture of what is truly happening.
Joined: Jan 08, 2002
Sorry for making a mistake in posting my message. I tested the application with Oracle 10g and 9i Java Virtual Machine by loading these class into Oracle database and run, to my suprise the version with static vars run 10 slower.
Here is the step to test: 1. compile java files
2. use loadjava -u db_username/db_password AESR.class to load it into Oracle database 3. log in Oracle with the same database user above. Use this code to declare the function
4. Run the funtion with "set timing on" and "select testR from dual;"
Run this normal version with the same step as above
As we have tested these versions run nearly the same if it runs with JDK1.4 on Linux, but I don't know why it is too different in Oracle VM. Have anyone got experience in profiling Oracle VM?
Well, I'll tell you, friend. I just looked a bit more closely at these two programs, and I noticed that the first one's got one more zero in that right big old number in the "for" loop. Not rightly sure what that big old number does, but I hear tell it has some kind of effect on the running time of a program. Now, adding one more zero might not seem like much of a change, being just a zero and all, but maybe, just maybe, that might be your explanation right there.