Open Side Menu Go to the Top
Register
TimingTest: C# vs Java TimingTest: C# vs Java

04-27-2013 , 12:29 AM
a few thoughts:

- overall, the think the relative performance between java and c# should be pretty close

- your loops are measuring memory access time as much as they are the sqrt function. if you replace the square root with a multiplication, i bet you see a speedup of like 0x to 4x despite the fact that the actual assembly instruction for multiply is more like 10-20x faster than the sqrt. the memory access is masking the latency of the arithmetic instructions (even if it hits the cache perfectly)

-using a square root function as the point of comparison possibly has some extra complications because of implementation. There are several different common ways to implement a square root on intel cpus... full IEEE sqrt microcoded instruction, reciprocal sqrt + division, reciprocal approximate + some cycles of newton-raphson, etc... the implementations for c# and java might be different (I dont know... and might also differ depending on level of optimization).

- theres nothing wrong with using a float or double as a loop counter.

edit:

- neither java nor c# can take advantage of SSE instructions because they dont support aligned memory allocation
TimingTest: C# vs Java Quote
04-27-2013 , 09:01 AM
Quote:
Originally Posted by sng_jason
a few thoughts:

- overall, the think the relative performance between java and c# should be pretty close

- your loops are measuring memory access time as much as they are the sqrt function. if you replace the square root with a multiplication, i bet you see a speedup of like 0x to 4x despite the fact that the actual assembly instruction for multiply is more like 10-20x faster than the sqrt. the memory access is masking the latency of the arithmetic instructions (even if it hits the cache perfectly)

-using a square root function as the point of comparison possibly has some extra complications because of implementation. There are several different common ways to implement a square root on intel cpus... full IEEE sqrt microcoded instruction, reciprocal sqrt + division, reciprocal approximate + some cycles of newton-raphson, etc... the implementations for c# and java might be different (I dont know... and might also differ depending on level of optimization).

- theres nothing wrong with using a float or double as a loop counter.

edit:

- neither java nor c# can take advantage of SSE instructions because they dont support aligned memory allocation
Yeah memory access times are a factor even if they're all cache hits. It all gets back to the basic question of what are we trying to measure with this test.
TimingTest: C# vs Java Quote
04-28-2013 , 02:32 PM
Quote:
Originally Posted by sng_jason
-using a square root function as the point of comparison possibly has some extra complications because of implementation. There are several different common ways to implement a square root on intel cpus... full IEEE sqrt microcoded instruction, reciprocal sqrt + division, reciprocal approximate + some cycles of newton-raphson, etc... the implementations for c# and java might be different (I dont know... and might also differ depending on level of optimization).
The implementations very much are different. You can see the OpenJDK implementation (some lovely hand-optimized C code) here, while C# should eventually compile Math.Sqrt() to an fsqrt assembly instruction, as you can see here.
TimingTest: C# vs Java Quote
04-29-2013 , 01:19 AM
I think C# is easier than Java, i would prefer C# for the beginners. coding is little different from each other.
TimingTest: C# vs Java Quote
05-01-2013 , 02:22 PM
I wouldn't underestimate the JVM. I think its gotten better than the CLR (I might be using the wrong term here) at inline optimizations.
TimingTest: C# vs Java Quote
05-01-2013 , 02:23 PM
Quote:
Originally Posted by CharlesThomas
I think C# is easier than Java, i would prefer C# for the beginners. coding is little different from each other.
I would agree with that since it is much easier to wire up a GUI and events in C# assuming you are using Visual Studio. That is important for beginners.
TimingTest: C# vs Java Quote

      
m