Posted: Sat Aug 02, 2008 12:49 pm Post subject: RE:[Performance] Beat the pants off of my best time
While I do not have a proper environment to test this in optimized form, I ran a naive Sieve of Erastothenes through the O'Caml top-level.
code:
# let t = Sys.time ()
and a = Array.make 2_097_151 true in
for i = 1 to Array.length a - 1 do
if a.(i) then
for j = 2 to Array.length a / (i + 1) do
a.(j * (i + 1) - 1) <- false
done
done;
Printf.printf "%f\n" (Sys.time () -. t);;
3.875000
- : unit = ()
#
zylum
Posted: Sat Aug 02, 2008 1:07 pm Post subject: RE:[Performance] Beat the pants off of my best time
Brightguy, pretty much what I did but I used ints instead of chars XD
wtd
Posted: Mon Aug 04, 2008 1:17 am Post subject: RE:[Performance] Beat the pants off of my best time
code:
chris@frankenstein:~/Documents$ cat primes.ml
let t = Sys.time ()
and a = Array.make 2_097_151 true in
for i = 1 to Array.length a - 1 do
if a.(i) then
for j = 2 to Array.length a / (i + 1) do
a.(j * (i + 1) - 1) <- false
done
done;
Printf.printf "%f\n" (Sys.time () -. t);;
chris@frankenstein:~/Documents$ ocamlopt primes.ml -o primes
chris@frankenstein:~/Documents$ ./primes
0.536032
chris@frankenstein:~/Documents$
wtd
Posted: Mon Aug 04, 2008 9:48 pm Post subject: RE:[Performance] Beat the pants off of my best time
let
val t = Time.now()
val a = Array.array(2097151, true)
in
Array.update(a, 0, false);
Array.appi(fn (i, x) =>
if x then
let
val number = i + 1
in
ArrayUtils.fromToByDo(a, number * 2 - 1, Array.length a - 1, number,
fn (a, i, _) => Array.update(a, i, false))
end
else ()) a;
let
val t' = Time.now()
val diff = Time.-(t', t)
in
print ((IntInf.toString(Time.toMilliseconds diff)) ^ "\n")
end
end;