These are not the best benchmarks, but Python is indeed as slow as Perl, which I find insane considering that Python has 100-1000 more people working on the interpreter and performance has been a big emphasis the last few years.
The benchmark is not representative of how Python is actually used in practice. It ignores the existence of libraries (explicitly). For example, If numpy, pytorch were used for matmul, the results would be completely different.
Benchmarking 20 programming languages on N-queens and matrix multiplication
91–100 of 194 posts
Re: Benchmarking 20 programming languages on N-queens and matrix multiplication
#92I love a good benchmark, thanks for putting this together! However, I have a bit of feedback. First, the graph is misleading, stacking times with languages that have half the implementation, they appear faster, until you dig in. I'd suggest producing an alternate graph that shows only the implemented puzzles in every language, or make a unique graph for every language:puzzle. Second, the examples are taken from roset…
Re: Benchmarking 20 programming languages on N-queens and matrix multiplication
#93I love a good benchmark, thanks for putting this together! However, I have a bit of feedback. First, the graph is misleading, stacking times with languages that have half the implementation, they appear faster, until you dig in. I'd suggest producing an alternate graph that shows only the implemented puzzles in every language, or make a unique graph for every language:puzzle. Second, the examples are taken from roset…
Re: Benchmarking 20 programming languages on N-queens and matrix multiplication
#94> It is obvious that c[i], b[k] and a[i][k] can be moved out of the inner loop to reduce the frequency of matrix access. [...] However, most other languages cannot optimize this nested loop. If we manually move a[i][k] to the loop above it, we can often improve their performance. This is only true when three matrices are independent of each other, and also why C has a `restrict` qualifier that enables this assumption…
In some cases there are other reasons for hoiting the dereference too. For example, Crystal will check if the array access is out of bounds and by hoisting variables that will be done a lot less seldom, which can have huge effects for code that does a lot of that, like matmul.
Re: Benchmarking 20 programming languages on N-queens and matrix multiplication
#95I wondered why rust is so far behind C/nim/zig, they should have similar behaviour. The difference is mostly in matmul. I see how C, for an n x n matrix, does 2 allocations, while rust does n+1. C's matrix rows are right next to each other, rusts are probably all over the place. Didn't look at nim or zig. Maybe a slice of slice of double would perform better than a vec of vec of double? Then again, an argument can be…
rust is equivalent to C when using static allocation i sent a pr to fix it
Edit: I have tried making an iterator-based version to elide bound checks, but had to resort to unsafe, and it's barely 50% faster than the original rust version (not as fast as C): https://gist.github.com/anisse/6b580628206293ef242faa7db6219...
Edit 2: updated, and my rust iterator version now ~equivalent to C with no unsafe.
Edit 3: too late, the repo has been updated with an other iterator-based version that is just as fast.
Re: Benchmarking 20 programming languages on N-queens and matrix multiplication
#96Earlier quoted context omitted.
rust is equivalent to C when using static allocation i sent a pr to fix it
Doesn't your PR monomorphize the function every time N is changed ? I realize it's simpler since it keeps the structure, simplifies allocation of arrays, and elides bound check. But it explodes generated code size and matrix size can't be changed at runtime, which doesn't really match C. Edit: I have tried making an iterator-based version to elide bound checks, but had to resort to unsafe, and it's barely 50% faster…
also, `const N` is used in rust's nqueen test, so figured it would be fine.
someone posted an `.iter().zip()` solution which benchmarks only a little slower (+10ms) than static allocation:
https://github.com/attractivechaos/plb2/pull/4#issuecomment-...
Re: Benchmarking 20 programming languages on N-queens and matrix multiplication
#97Earlier quoted context omitted.
Doesn't your PR monomorphize the function every time N is changed ? I realize it's simpler since it keeps the structure, simplifies allocation of arrays, and elides bound check. But it explodes generated code size and matrix size can't be changed at runtime, which doesn't really match C. Edit: I have tried making an iterator-based version to elide bound checks, but had to resort to unsafe, and it's barely 50% faster…
C, Nim and Zig all benefit from static allocation and it's available in rust, so seems fair? also, `const N` is used in rust's nqueen test, so figured it would be fine. someone posted an `.iter().zip()` solution which benchmarks only a little slower (+10ms) than static allocation: https://github.com/attractivechaos/plb2/pull/4#issuecomment-...
I saw the update to the PR, but I still prefer my collect()-based version :-)
Re: Benchmarking 20 programming languages on N-queens and matrix multiplication
#98Neat! The Julia matmul implementation has its rows and columns flipped though - unlike C, Julia uses row-major matrices. This has large implications for speed. Also, the code may be much faster if you enable SIMD in the function, which is disabled in the code because a) the code unnecessarily checks bounds at every index instead of at the top of the function, and b) float SIMD is opt-in since SIMD changes the roundin…
Re: Benchmarking 20 programming languages on N-queens and matrix multiplication
#99I wondered why rust is so far behind C/nim/zig, they should have similar behaviour. The difference is mostly in matmul. I see how C, for an n x n matrix, does 2 allocations, while rust does n+1. C's matrix rows are right next to each other, rusts are probably all over the place. Didn't look at nim or zig. Maybe a slice of slice of double would perform better than a vec of vec of double? Then again, an argument can be…
Re: Benchmarking 20 programming languages on N-queens and matrix multiplication
#100I love a good benchmark, thanks for putting this together! However, I have a bit of feedback. First, the graph is misleading, stacking times with languages that have half the implementation, they appear faster, until you dig in. I'd suggest producing an alternate graph that shows only the implemented puzzles in every language, or make a unique graph for every language:puzzle. Second, the examples are taken from roset…