Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I don't have exact numbers on the efficiency of the JVM vs the CLR, but the difference, if any, is likely to be small. </p> <p>However, on the language side, C# does have some more low level constructs than Java, which would allow for more optimization. </p> <p>Constructs such as:</p> <ul> <li><p>User defined value types. Fast to allocate, no memory overhead (which is 12 bytes per reference type in both the CLR and JVM if I remember correctly). Useful for things that let themselves naturally be expressed as values, like vectors and matrices. So mathematical operations. Combine this with <code>ref</code> and <code>out</code> to avoid excessive copying of these large value types.</p></li> <li><p>Unsafe blocks of code that allow a little more 'close to the metal' optimization. For example, while the CLR and JVM can avoid array bounds checks in some situations, in a lot of cases, they can't and every array access requires a check whether or not the index is still within bounds of the array. Using unsafe code here allows you to access the memory of the array directly with pointers and circumvent any bounds checks. This can mean a significant saving. And on the very low level side, there's also <code>stackalloc</code> which allows you to allocate arrays directly on the stack, whereas a normal array is allocated on the heap, which is slower, but also more convenient. I personally don't know any practical applications of <code>stackalloc</code>. </p></li> <li><p>True generics, unlike the type erasing generics of Java, avoiding unneeded casting and boxing. But if this is a problem in your Java program, it can easily be solved with some extra work (switching from for example a <code>ArrayList&lt;Integer&gt;</code> to a custom type that internally uses an <code>int[]</code> buffer.)</p></li> </ul> <p>This all seems biased towards C# and I do think C# has better low level language constructs available that can help with performance. However, I doubt these differences really matter (and they might not even apply in your case, using pointers gains you nothing if all you do is database access, where Java might be faster) if the choice impedes you in some other way (like going cross platform). Go for correctness, the platform that matches your requirements, rather than minor performance differences. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload