Wasn’t there some sort of switch in the Sun JRE to use a less exact but much faster variant of Math?
I’m using lang.Math trig functions in my software renderer but i’m not using many trig ops in the main loop, just in the matrix class. I used both the lang.Math functions and a lookup table in a mode7 rendering applet and I didn’t see any performance difference between the two. Both methods gave the same frame rate.
[quote]Wasn’t there some sort of switch in the Sun JRE to use a less exact but much faster variant of Math?
[/quote]
Your thinkign of the “strictfp” loophole. Its a very very tiny loophole. Just enough to allow the Intel fused multiply and add.
Intel x86 processors don’t have a fused multiply and add (the IA64/Itanium does). These fused instructions maintain additional precision which is not permitted by non strictfp java. The relaxtion which accompanied strictfp only allows additional exponent range during intermediate calculations. This permits the use of the Intel 80 bit reals for temporaries (provided the FPU is running in the mode which restricts the precision to that of normal double/float as appropriate).
There was a JSR (84) which proposed further relaxation to allow the use of fused multiply/add instructions as found in PowerPC for example. Unfortunately this was withdrawn apparently due to problems setting up the expert group.
http://www.jcp.org/en/jsr/detail?id=84
Okie I’ll cop to being confused by all the various register level processor issues. Not my area of expertise
Thanks for the clarification on whats what.
If you look at his Benchmark.java source code, you’ll notice he simply goes from 1->10million and computes Math.sin, etc. for each increment of 1. If we clamped the range so it fell between 0 and 2PI, would that not return the same values? IE, alter his loop to look like:
double clampedI = 0.0;
while (i < trigMax)
{
clampedI = i%(2*Math.PI);
sine = Math.sin(clampedI);
cosine = Math.cos(clampedI);
tangent = Math.tan(clampedI);
logarithm = Math.log(i);
squareRoot = Math.sqrt(i);
i++;
}
Perhaps I’m off, (was up very late last night)… But, if the math is accurate, this gives a very nice performance boost. (from 65s -> 13s on my P4 2.0G machine)
Fire away.
Yeah, but that’s not really relevant, is it? You’re changing the program for just java, which is cheating. So you’d have to change it for all languages and measure again on all languages.
Its a good program optimization… the kind oif algorythmic optimization that in the real-world often does the most good for your program.
But as a comparison, I agree, you would need to do the same to the C code.
Just points again to the difference between benchmarking and writing real code.
Yep, I agree it’d have to be done across the board. But still, if the optimization brought c++'s trig score from 3.5secs -> 0secs (giving best case) and Java’s trig score from 57secs -> 15secs (the speedup I saw), you’d still end up with c++'s total score being ~ 45 and Java’s about 60 (or slightly better than, or at least comparable to C#)
[quote](or slightly better than, or at least comparable to C#)
[/quote]
If you wouldn’t update the C# benchmark too, maybe, maybe not. But you have to. Again, apples to apples and all… In any way you’d have to measure again instead of just speculate.
As I see it, java’s bad trig score is because of java’s spec being more demanding than the other language’s specs towards trig precision.
Although the benchmark is just a benchmark and not real-life code, it still demonstrates this difference.
You can’t change that by changing the benchmark although I agree that if changing the benchmark to more real life code will make the results closer together demonstrates you must never draw too much conclusions from benchmark results.
For real performance, you might have to use look-up tables anyway although a less precise but fast alternative would be of course very welcome.
The most worrying aspect of the benchmark that’s circulating the net at the moment is the C# to Java performance, not the C/C++ comparison. I’d like to know how M$ have gotten some operations so fast compared to Java.
Cas
What’s so worrying? As I see it, C# performs worse than java, except for trigonometry.
yes, and if C# & java is “the same thing”, how come java is slower than C# ?
Ah, there was another benchmark floating around which I was referring to that shows apples->apples Java and C# along with about 100 other mostly obscure languages. The C# code generation’s good.
It’s mainly a bummer if you’re doing trig of course And games programmers do tend to use those trig functions rather a lot…
Cas
[quote]yes, and if C# & java is “the same thing”, how come java is slower than C# ?
[/quote]
You’re losing me. Is it? :
Discounting trig, scores in this benchmark are
java: 46.1
C#: 61.2
[quote]Ah, there was another benchmark floating around
[/quote]
Googled around but didn’t find it. You have a link?
You mean the windows::developer benchmark?
quote from the summary:
and
[quote]C# is significantly faster (3–4 times) at memory
allocation than Java.
[/quote]
which is worrying I suppose. The benchmark mentioned in this thread didn’t measure memory allocation.
I was talking about trig!
C#: 4.1
Java: 57.1
C# is 12 times faster than Java!
I created a trig lookup table. It’s only 4 times as fast as java.lang.Math with float accuracy on the client. The strange this is when I use the server, performance severely degrades: with the table more (almost 4x as slow) as java.lang.math (takes ‘only’ 30% more time).
Maybe ‘microbenchmarking problem’ (which the ‘osnews’ benchmark also suffers from)? Or a server bug? Hard to tell… :-/
[quote]You mean the windows::developer benchmark?
[/quote]
To paraphrase one of my favorite Mark Twain quotes:
“There are three kinds of lies. Lies, damn lies, and benchmarks.”
When i talk I tell the people in the room not to trust anyones benchmarks. Don’t trust those with a vested interest, because they all cheat (so called “benchmarketing”).
Don’t naively trust third party benchmarks because you don’t know how much they really knew about the black art of benchmarking (usually its next to nothing.)
Its just like statistics. The numbers mean nothing until they are interpreted. Interpretation is prone to error. Look at the WHOLE study and use your own brain to decide if the methodology really warrants the conclusions. And then do your OWN tests with your OWN apps, because they are the final performance measure you really care about.
“50% of the US highschool graduates graduated in the bottom half of their class!” – “How to lie with statistics”