LINUX.ORG.RU

История изменений

Исправление Bad_ptr, (текущая версия) :

let n = 3000000 in
  let _ = Random.self_init() and
      rarray = Array.init n (fun x -> Random.float (float x)) and
      t = Sys.time() in
    let r = Array.fold_left (fun a b -> a +. (b ** 2.0)) 0.0 rarray; in
      let new_t = Sys.time() in
        Printf.printf "Result: %f\n" r;
        Printf.printf "Took %fs\n" (new_t -. t);
;;
> ocamlc random_bench.ml
> time ./a.out

Result: 9002077513758873600.000000
Took 0.260000s
./a.out  1,90s user 0,01s system 99% cpu 1,910 total

?))

Исходная версия Bad_ptr, :

let n = 3000000 in
  let _ = Random.self_init() and
      rarray = Array.init n (fun _ -> Random.float (float n)) and
      t = Sys.time() in
    let r = Array.fold_left (fun a b -> a +. (b ** 2.0)) 0.0 rarray; in
      let new_t = Sys.time() in
        Printf.printf "Result: %f\n" r;
        Printf.printf "Took %fs\n" (new_t -. t);
;;
> ocamlc random_bench.ml
> time ./a.out

Result: 9002077513758873600.000000
Took 0.260000s
./a.out  1,90s user 0,01s system 99% cpu 1,910 total

?))