[Shootout-list] nsieve implementations in C, OCaml, Python, and Scheme

Dima Dorfman d+shootout@trit.org
Tue, 14 Dec 2004 14:35:38 +0000


I wrote implementations of the nsieve test in C, OCaml, Python, and
Scheme. They are, respectively,

  http://www.trit.org/~dima/home/nsieve/nsieve.c
  http://www.trit.org/~dima/home/nsieve/nsieve.ml
  http://www.trit.org/~dima/home/nsieve/nsieve.py
  http://www.trit.org/~dima/home/nsieve/nsieve.scm

The C and OCaml modules include two implementations each; one stores
one flag per array element, and the other uses an array to store
bitmaps. Can the latter be considered fair? I wouldn't call it an
"array of boolean flags" (neither language lets you access it as an
array), but someone that needed such a structure in a real program and
cared about speed would implement it like that. Regardless of that
decision, one of the implementations should be removed from the files
before posting to avoid sabotaging the LOC score. This technique does
not make sense for Python, and I didn't try it for Scheme.

In my tests, the OCaml compiler beats gcc by about 10% for this case.

Dima.