File: benchs.ml

package info (click to toggle)
ocaml-iter 1.9-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 328 kB
  • sloc: ml: 2,503; makefile: 39
file content (32 lines) | stat: -rw-r--r-- 901 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
module S = Iter
open Iter.Infix

[@@@ocaml.warning "-5"]

let small = [ 10; 20; 50; 100; 500 ]
let medium = small @ [ 1000; 10_000; 100_000 ]
let big = medium @ [ 500_000; 1_000_000; 2_000_000 ]
let bench_fold n = 0 -- n |> S.fold ( + ) 0 |> ignore

let bench_flatmap n =
  0 -- n |> S.flat_map (fun i -> i -- (i + 5)) |> fun _ -> ()

let bench_product n = S.product (0 -- n) (0 -- n) (fun _ -> ())

let _ =
  List.iter
    (fun (name, bench, sizes) ->
      Format.printf "-------------------------------------------------------@.";
      Format.printf "bench %s@." name;
      List.iter
        (fun n ->
          let name = name ^ " on " ^ string_of_int n in
          let res = Benchmark.throughput1 2 ~name bench n in
          Benchmark.tabulate res)
        sizes)
    [
      "fold", bench_fold, big;
      "flatmap", bench_flatmap, medium;
      "product", bench_product, small;
    ];
  ()