I was looking to see how ruby did as far as performance goes and found this webpage. I was very sad looking at the code this guy used. He lacked any understanding of variable precision in any language. He also lacked knowledge of optimizers. Notably, the C output gave him erroneous results due to overflow conditions. He should have used long and not int.
However, I was surprised that C didn't optimize the loop completely out the same way Go did. It's clear that Go won simply because it didn't loop at all. Like I mentioned, C should have had nearly the same result Go did if the compiler worked the way it should have.
Yes, your results are much more in line with what I was expecting. However, simple loop constructs aren't very useful as a benchmark for performance. It would be much more useful to at least do a bubble sort or insertion sort.
Java and Node both surprised me, too, but especially the latter. I'll definitely give Node a closer look after this.
Very disappointed with Python today. Even an 8+ year old version of SpiderMonkey I have lying around finishes the task in one third of the time.
I did the optimized C test incorrectly. It looks like the compiler skipped the algorithm entirely because it didn't see any reference to the result. After the fix it finishes in 75-80 ms.
8 comments
0 u/vastrightwing [OP] 07 Nov 2019 21:29
I was looking to see how ruby did as far as performance goes and found this webpage. I was very sad looking at the code this guy used. He lacked any understanding of variable precision in any language. He also lacked knowledge of optimizers. Notably, the C output gave him erroneous results due to overflow conditions. He should have used long and not int.
However, I was surprised that C didn't optimize the loop completely out the same way Go did. It's clear that Go won simply because it didn't loop at all. Like I mentioned, C should have had nearly the same result Go did if the compiler worked the way it should have.
0 u/psimonster 07 Nov 2019 23:48
My results:
C without compile options (and the correct answer) and Go gave about the same times, between 250 and 320 ms.
C compiled with -O3 on gcc finished in 1 or 2 ms.
Python 3.8 about 9 s
Ruby 2.2.1 about 12 s (with the wrong answer)
Node between 100 and 200 ms
Java between 90 and 160 ms
I don't do PHP.
0 u/vastrightwing [OP] 08 Nov 2019 02:05
Yes, your results are much more in line with what I was expecting. However, simple loop constructs aren't very useful as a benchmark for performance. It would be much more useful to at least do a bubble sort or insertion sort.
0 u/psimonster 09 Nov 2019 15:24
My results for a bubble sort on a reversed 10000 integer array:
Java: 91-96 ms
C (no opt): 167-237 ms
C (-O3): 1 ms
Go: 267-329 ms
Node JS: 141-168 ms
Python2.7: 19-20 s
Python3.8: 23-25 s
Ruby 2.2.10: 5-6 s
0 u/vastrightwing [OP] 09 Nov 2019 16:10
I'm impressed. Java surprises me. Considering it's a byte code interpreter, it gets a very respectable benchmark. I had no idea Node was so optimized.
Thanks!
0 u/psimonster 09 Nov 2019 17:36
Java and Node both surprised me, too, but especially the latter. I'll definitely give Node a closer look after this.
Very disappointed with Python today. Even an 8+ year old version of SpiderMonkey I have lying around finishes the task in one third of the time.
I did the optimized C test incorrectly. It looks like the compiler skipped the algorithm entirely because it didn't see any reference to the result. After the fix it finishes in 75-80 ms.
0 u/libman 08 Nov 2019 05:06
An old and terrible benchmark. I've posted a much better ones here recently, like: kostya/benchmarks, TechEmpower, etc.
Scripting languages are a joke when it comes to real-world performance. And Go is behind serious C alternatives like Nim, D, and Rust.
0 u/vastrightwing [OP] 08 Nov 2019 09:46
Interesting. I was surprised by the sheer number of "frameworks" out there. It seems there's a new one every week.