I've checked some run times on my M1 mac mini, and have realised the C run time of 2.1s for n-body is the figure from the benchmark game itself, which is 50 million iterations on a very old i5. It would have made sense if they'd run the C version on their M4 pro and used the same number of iterations to get a true comparison there.
Obviously the main point of the article is to compare different python optimisations, however "rewrite it in C/C++/rust/Go" is an option that should be considered, and none of his optimisations on his M4 Pro beat the C option on my 6-year old M1 mac mini.
The rest of the numbers in the blog post use a 500k iterations for the nbody simulation. Here's my numbers on the M1 mac using the default Clang installed with xcode:
Here are a few naive un-optimised single-thread #8 programs transliterated line-by-line literal style into different programming languages from the same original.
Obviously the main point of the article is to compare different python optimisations, however "rewrite it in C/C++/rust/Go" is an option that should be considered, and none of his optimisations on his M4 Pro beat the C option on my 6-year old M1 mac mini.
The rest of the numbers in the blog post use a 500k iterations for the nbody simulation. Here's my numbers on the M1 mac using the default Clang installed with xcode:
I used the fastest C code that doesn't use intrinsics at [1] and compiled withclang -O3 -march=native nbody-gcc-6.c -o nbody.clang6
Used the python version from [2].
[1] http://benchmarksgame-team.pages.debian.net/benchmarksgame/p...
[2] https://github.com/cemrehancavdar/faster-python-bench/tree/m...