Live data from Hacker News

Benchmarking 20 programming languages on N-queens and matrix multiplication

github.com

161–170 of 194 posts

Re: Benchmarking 20 programming languages on N-queens and matrix multiplication

#161
post #152

Earlier quoted context omitted.

...and many jitted vms do not even reach a stable point at all, there was a big paper on this a couple of years ago.

This? https://tratt.net/laurie/blog/2018/why_arent_more_users_more...

Yes, this is the one. Time flies! And VM jits didn't change all that much.

Re: Benchmarking 20 programming languages on N-queens and matrix multiplication

#162

Why is c# so slow for Matmul compared to java?

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.

Thanks for the explanation. Yes this make sense to me.

Re: Benchmarking 20 programming languages on N-queens and matrix multiplication

#163

Why is c# so slow for Matmul compared to java?

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.

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

Re: Benchmarking 20 programming languages on N-queens and matrix multiplication

#164

Earlier quoted context omitted.

Yes, but the author claims the longest JIT warmup is 0.3 seconds, so it's not an important issue in these benchmarks that take several seconds.

0.3s is significant for a task that only takes 1.14s

We don't know that OpenJDK was "Some JIT-based language runtimes take up to ~0.3 second to compile and warm-up"

Maybe that was PyPy with program times >5 seconds.

Re: Benchmarking 20 programming languages on N-queens and matrix multiplication

#166

Earlier quoted context omitted.

This is really overstating how hard it is to compete with matrix multiply libraries. The main reason those libraries are so big and have had so much work invested in them is their generality: they're reasonably fast for almost any kind of inputs. If you have a specific problem with constraints you can exploit (e.g. known fixed dimensions, sparsity patterns, data layouts, type conversions, etc.), it's not hard at all…

> This is really overstating how hard it is to compete with matrix multiply libraries. I'll file this under "talk is cheap". :) I tried it last year and got within 50% of BLAS. Getting above that is tons of work. Which you have to repeat for every processor model, NUMA, and every combination of matrix type (long thin, short wide, etc).

This gets to 90% of BLAS: https://github.com/dsharlet/array/blob/38f8ce332fc4e26af0832...

The less involved versions still get ~70%.

But this is also quite general. I’m claiming you can beat BLAS if you have some unique knowledge of the problem that you can exploit. For example, some kinds of sparsity can be implemented within the above example code yet still far outperform the more general sparsity supported by MKL and similar.

Re: Benchmarking 20 programming languages on N-queens and matrix multiplication

#167
A curious thing about Swift: after https://github.com/attractivechaos/plb2/pull/23, the matrix multiplication example is comparable to C and Rust. However, I don’t see a way to idiomatically optimise the sudoku example, whose main overhead is allocating several arrays each time solve() is called. Apparently, in Swift there is no such thing as static array allocation. That’s very unfortunate.

Re: Benchmarking 20 programming languages on N-queens and matrix multiplication

#168

Earlier quoted context omitted.

> This is really overstating how hard it is to compete with matrix multiply libraries. I'll file this under "talk is cheap". :) I tried it last year and got within 50% of BLAS. Getting above that is tons of work. Which you have to repeat for every processor model, NUMA, and every combination of matrix type (long thin, short wide, etc).

This gets to 90% of BLAS: https://github.com/dsharlet/array/blob/38f8ce332fc4e26af0832... The less involved versions still get ~70%. But this is also quite general. I’m claiming you can beat BLAS if you have some unique knowledge of the problem that you can exploit. For example, some kinds of sparsity can be implemented within the above example code yet still far outperform the more general sparsity supported by MKL…

I don't believe you. OpenBLAS is multithreaded but the code you posted is single-threaded. The inner kernel isn't very well optimized either. So, no way.

Re: Benchmarking 20 programming languages on N-queens and matrix multiplication

#169

Earlier quoted context omitted.

This gets to 90% of BLAS: https://github.com/dsharlet/array/blob/38f8ce332fc4e26af0832... The less involved versions still get ~70%. But this is also quite general. I’m claiming you can beat BLAS if you have some unique knowledge of the problem that you can exploit. For example, some kinds of sparsity can be implemented within the above example code yet still far outperform the more general sparsity supported by MKL…

I don't believe you. OpenBLAS is multithreaded but the code you posted is single-threaded. The inner kernel isn't very well optimized either. So, no way.

I should have mentioned somewhere, I disabled threading for OpenBLAS, so it is comparing one thread to one thread. Parallelism would be easy to add, but I tend to want the thread parallelism outside code like this anyways.

As for the inner loop not being well optimized... the disassembly looks like the same basic thing as OpenBLAS. There's disassembly in the comments of that file to show what code it generates, I'd love to know what you think is lacking! The only difference between the one I linked and this is prefetching and outer loop ordering: https://github.com/dsharlet/array/blob/master/examples/linea...

Re: Benchmarking 20 programming languages on N-queens and matrix multiplication

#170

A curious thing about Swift: after https://github.com/attractivechaos/plb2/pull/23 , the matrix multiplication example is comparable to C and Rust. However, I don’t see a way to idiomatically optimise the sudoku example, whose main overhead is allocating several arrays each time solve() is called. Apparently, in Swift there is no such thing as static array allocation. That’s very unfortunate.

Figure updated. Now swift is pretty fast on nqueen+matmul but it has the longest green bar (i.e. longest running time for sudoku). This looks ... interesting.

There are only 20 thousand array allocations in total, not a lot. Javascript also has these many arrays allocated/deallocated but it is 4 times as fast.

Post reply on HN