sieve.mlton
Doug Bagley
doug@bagley.org
Mon, 11 Jun 2001 06:35:55 -0500 (CDT)
Stephen Weeks wrote:
>
> Here is a version of sieve that uses a bool array instead of a
> Word8Array.array and also has the nested loop in a more idiomatic style. On my
> machine, it runs in about 65% of the time of your version, for reasons I don't
> understand.
Thanks I see the speedup too.
Recently I had noticed that on my machine, the programs that use char
arrays (like GCC) to represent booleans ran a lot faster than the ones
that use int arrays (which are larger and presumably don't fit into
the CPU cache).
So I recoded the Ocaml source to use a string instead of an bool array
(which I presume uses a full word to represent a boolean), and I got a
2.5x speedup.
Now the old SML programs were based on using lists to calculate the
sieve (I'd copied them from somewhere off the net) and were dreadfully
slow. So I changed to emulate the Ocaml source and likewise use char
arrays. That change made a dramatic speedup over the original, but I
should have checked bool arrays! So thanks for checking up for me.
Cheers,
Doug