3 ms·
Why is c# so slow for Matmul compared to java?
by akashcoach 3y ago
Why is c# so slow for Matmul compared to java?
- mlhpdx 3y agoThe implementation isn’t using any modern C# features?
- akashcoach 3y agoWhich modern features do you mean? Java and C# code looks similar to me.
- neonsunset 3y agoUnfortunately it doesn't. The newest and hottest way to do this is to either use bespoke matmul from System.Numerics.Tensors or at least using Vector<T> for SIMD (which is trivial and not "the last mile" optimization it often seems to be).
- useerup 3y agoI believe because the C# version has been written using rectangular arrays. This requires every array access to use a multiplication. The Java version uses array-of-arrays and hoisting the inner array out before accessing it in the inner loop. C# also has arrays-of-arrays, and could (should) be written in the same manner.
- akashcoach 3y agoThanks for the explanation. Yes this make sense to me.
- iruoy 3y agoI've just done this and it has been merged. The benchmarks table and image haven't been updated yet. But this should bring the C# result to ~2s instead of 4.67s