This micro-benchmark quickly caught the attention of programmers from various backgrounds and snowballed into a miniature language comparison.
We submitted a simple OCaml implementation that turned out to be roughly as fast as the C implementation (faster than -O2 but slower than -O3 -ffast-math) and slightly shorter:
let n = 5000After several days of conferring and much performance-related deliberation, the Lisp community announced their completion of a longer and slower but "more flexible" solution written in Lisp.
let () =
let i = ref 0 in
for c=2 to n do
for b=1 to c-1 do
let a = sqrt(float(c*c - b*b)) in
if float(truncate a) = a then incr i
print_endline (string_of_int !i)
For a thorough introduction to high-performance computing using OCaml, read OCaml for Scientists.