Forums Register Login
static vars vs local vars
hi all,

The first class uses static variable :

and the second class uses local vars

I have run the test and the local variable version run 10 times faster than the version using static var.

Could you pls explain why the local variable version runs faster? I thought that the static must run faster because the local variables are freed after method call but static variables are not

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 ]
which jvm (1.1, 1.2?), which flags (-sever y/n?).

jvms: 1.4.2, 1.5.0
-server y/n
-MAX 100,000 and 10,000,000
no significant differences measured.

I'm glad to have a benchmark template, to check all those observations myself, which avoids useless tuning-ideas.

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.
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
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.
Dear all,

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

SQL code

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.

efh - observer of the week!
Run away! Run away! Here, take this tiny ad with you:
Rocket Oven Kickstarter - from the trailboss

This thread has been viewed 960 times.

All times above are in ranch (not your local) time.
The current ranch time is
Jul 20, 2018 22:17:14.