Generating 20,000 primes on the Apple M1
2023-03-10
versus an i7-10700k, a Pentium G4400, and a Raspberry Pi 4!
Sometime last year, I wanted to see if I could write a C program to produce primes
in order by just brute force division: i.e., literally checking factors of each
iteration.
I'm still learning C and computer science in general, so excuse any rookie mistakes.
That said, one thing of note is how fast the Apple M1 (on my 2020 MacBook Air)
can generate these primes.
The program in question can be found on GitHub here.
I used clang with various optimization options rather than gcc to have parity between macOS and Linux (and it was faster than gcc anyway for whatever reason).
Anyway, if you want to try this yourself, you can totally run it multiple times,
and it'll append the results for each round in results.txt.
for i in {1..5}; do ./test.sh; done
If you want to do five rounds for example to see if you get similar results.
Time test on a 2020 M1 MacBook Air
1.4-ish seconds is ridiculously impressive!
It's a little slower printing to stdout.
Time test on my i7-10700k desktop
This was technically done in WSL2 (in Debian), but it is surprising that a laptop
with no fan outpaces this thing in single core performance, at least for this task.
Time test on a Dell 5040 with a Pentium G4400
No surprise that the 6th-generation Skylake Pentium will be the slower than the
previous two (especially the M1).
Time test on a Raspberry Pi 4 (2GB version)
Of course the Pi is the slowest of all of them. However, it's still impressive!