News for hackers. Stuff that matters.
Re:Benchmarking 20 programming languages on N-queens and mat... by akashcoach on Wednesday January 03, 2024 @10:18AM (#38855038)
Why is c# so slow for Matmul compared to java?
Re:Benchmarking 20 programming languages on N-queens and mat... by mlhpdx on Wednesday January 03, 2024 @10:42AM (#38855335)
The implementation isn’t using any modern C# features?
Re:Benchmarking 20 programming languages on N-queens and mat... by akashcoach on Wednesday January 03, 2024 @10:48AM (#38855412)
Which modern features do you mean? Java and C# code looks similar to me.
Re:Benchmarking 20 programming languages on N-queens and mat... by neonsunset on Wednesday January 03, 2024 @10:52AM (#38855476)
Unfortunately 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).
Re:Benchmarking 20 programming languages on N-queens and mat... by useerup on Wednesday January 03, 2024 @02:09PM (#38858356)
I 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.

Re:Benchmarking 20 programming languages on N-queens and mat... by akashcoach on Wednesday January 03, 2024 @04:20PM (#38860097)
Thanks for the explanation. Yes this make sense to me.
Re:Benchmarking 20 programming languages on N-queens and mat... by iruoy on Wednesday January 03, 2024 @05:39PM (#38860808)
I'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