ocaml: phase 5.1 euler10.ml baseline (sum of primes <= 100 = 1060, scaled-down PE10)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 25s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 25s
Sieve of Eratosthenes followed by a sum loop:
let sieve_sum n =
let s = Array.make (n + 1) true in
s.(0) <- false;
s.(1) <- false;
for i = 2 to n do
if s.(i) then begin
let j = ref (i * i) in
while !j <= n do
s.(!j) <- false;
j := !j + i
done
end
done;
let total = ref 0 in
for i = 2 to n do
if s.(i) then total := !total + i
done;
!total
Real PE10 asks for sum below 2,000,000; that's a ~2-3 second loop in
native OCaml but minutes-to-hours under our contended-host
spec-level evaluator. 100 keeps the run under 3 minutes while still
exercising the same algorithm.
110 baseline programs total.
This commit is contained in:
22
lib/ocaml/baseline/euler10.ml
Normal file
22
lib/ocaml/baseline/euler10.ml
Normal file
@@ -0,0 +1,22 @@
|
||||
let sieve_sum n =
|
||||
let s = Array.make (n + 1) true in
|
||||
s.(0) <- false;
|
||||
s.(1) <- false;
|
||||
for i = 2 to n do
|
||||
if s.(i) then begin
|
||||
let j = ref (i * i) in
|
||||
while !j <= n do
|
||||
s.(!j) <- false;
|
||||
j := !j + i
|
||||
done
|
||||
end
|
||||
done;
|
||||
let total = ref 0 in
|
||||
for i = 2 to n do
|
||||
if s.(i) then total := !total + i
|
||||
done;
|
||||
!total
|
||||
|
||||
;;
|
||||
|
||||
sieve_sum 100
|
||||
@@ -26,6 +26,7 @@
|
||||
"exception_handle.ml": 4,
|
||||
"exception_user.ml": 26,
|
||||
"euler1.ml": 233168,
|
||||
"euler10.ml": 1060,
|
||||
"euler2.ml": 4613732,
|
||||
"euler5.ml": 232792560,
|
||||
"euler6.ml": 25164150,
|
||||
|
||||
Reference in New Issue
Block a user