Finding a list of prime numbers is one of those benchmarks that’s pretty easy to code in any language. The trial division method won’t win any prizes for speed or creativity, but it’s a decent test of some basic hardware operations. Having written just such a prime checking programming in C, I was anxious to see whether a hand-coded assembly version would be any faster.
The short answer is that in my implementation, the 64-bit assembly version ran modestly faster on my machine (64-bit Intel Core i7) than the C code compiled in 64-bit mode with full optimizations. Note that this program simply spits out the total number of primes between 2 and MAX, not the actually primes themselves (often a rather long list).
x86 assembly- written for nasm, should run on Linux and MacOS X
C code – should run anywhere
Continue reading ‘Finding primes – simple assembly benchmark’