my crude benchmark results
John Gabriele
john3g@bestweb.net
Tue Jul 13 15:52:00 GMT 2004
On Jul 13, 2004, at 4:10 AM, Ranjit Mathew wrote:
> John Gabriele wrote:
>> for ( int i = 0; i < SIZE; ++i )
>> {
>> nums[i] = Math.random() * 3.14159 / 2.0;
>> }
>> I note that at least on the 3.4 branch and mainline,
> Math.random() is a synchronised method, so the loop
> above represents acquiring a lock on java.lang.Math
> and releasing it 50,000 times!
>> If you want to eliminate this factor, you can perhaps
> write out a pre-computed array and link that in. You'll
> also have to do it for the C version, just to be fair.
>> Ranjit.
>
Ok Ranjit, I think I know what you mean... and after this,
I'm done looking at this issue. :)
I wrote a silly little program that prints out my little
program, but instead of that snippet above, it writes in
something like:
double[] nums = {
0.28405076148495895, 0.9807300699397546,
0.9786110903212396, 1.5547419766709203, 1.1634867037019443,
0.4931688821767145, 0.05000789151159153, 1.4718826840605423,
1.3800820678374353, 0.8571551499989802,
0.0038028299188756142, 1.0666478646426427,
0.026130901307775383, 0.11471002838694738, 0.24784068060089662,
0.2354947785283451, 0.8352802991433658, 0.2124112033103205,
0.5650985446696697, 0.30992006534118643,
0.7737173897443732, 1.2266143429404666, 0.3089829703728145,
1.2045390919937518, 0.07481500162987234, 0.026065068706773394,
1.441708832990819, 0.3648059679407048, 0.11373783817185777,
0.49594222770011126,
0.6472283806778762, 1.0717648203332275, 1.398302991207293,
0.5712665441404836, 0.18189479047987736, 0.81656748076026,
0.780106969703009, 1.4335519338181488, 1.4548493455455738,
0.6723380165442411,
1.1592999359763154, 0.42787964752121066,
0.4628772726455968, 0.9673081931690998, 0.5028870208887453,
0.4296204629642612, 1.070557973156044, 0.41932517663661983,
0.5614911500513203, 0.7921576595394354,
[snip 49995 more lines]
};
The new source code file (Main2.java) is about 1MB. :) Wheee...
Then I built that new file with
gcj --main=Main2 -O3 -ffast-math -save-temps -fno-bounds-check -o
jfastest2.out Main2.java
and ran it a bunch of times to get a good average execution time:
> no -O3: 25.5 seconds
> with -O3: 24.2 seconds ( 5.1% improvement)
> with -O3 and -ffast-math: 23.2 seconds ( 9.0% improvement)
> also no-bounds-check: 22.2 seconds (12.9% improvement)
with giant pre-set array: 18.5 seconds (27.5% improvement)
As Forrest Gump once said, "And that's all I have to say about that". :)
---J
More information about the Java
mailing list