From 0a7d2a2411c10fdca2bd0788a28caa091120ef71 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Tue, 24 Jan 2017 23:43:15 +0100 Subject: [PATCH] update benchmarks (ignoring hamt); remove useless old script --- _oasis | 10 +--- benchs/mem_measure.ml | 119 --------------------------------------- benchs/run_bench_hash.ml | 8 +-- benchs/run_benchs.ml | 6 +- opam | 21 ++++--- 5 files changed, 21 insertions(+), 143 deletions(-) delete mode 100644 benchs/mem_measure.ml diff --git a/_oasis b/_oasis index 04c64ad5..1360c5d3 100644 --- a/_oasis +++ b/_oasis @@ -102,7 +102,7 @@ Executable run_benchs MainIs: run_benchs.ml BuildDepends: containers, qcheck, containers.data, containers.iter, - sequence, gen, benchmark, hamt + sequence, gen, benchmark Executable run_bench_hash Path: benchs/ @@ -130,14 +130,6 @@ Test all TestTools: run_qtest Run$: flag(tests) && flag(unix) -Executable mem_measure - Path: benchs/ - Install: false - CompiledObject: native - MainIs: mem_measure.ml - Build$: flag(bench) - BuildDepends: sequence, unix, containers, containers.data, hamt - Executable id_sexp Path: examples/ Install: false diff --git a/benchs/mem_measure.ml b/benchs/mem_measure.ml deleted file mode 100644 index d04360f1..00000000 --- a/benchs/mem_measure.ml +++ /dev/null @@ -1,119 +0,0 @@ - -(* goal: measure memory consumption *) - -(* number of words allocated *) -let mem_allocated () = - let gc = Gc.stat () in - gc.Gc.minor_words +. gc.Gc.major_words -. gc.Gc.promoted_words - -(* overhead in memory *) -let mem_occupied x = Objsize.size_kb (Obj.repr x) - -type stats = { - time: float; - occ: int; - alloc: float; -} - -let measure_time_mem f = - let mem_alloc1 = mem_allocated () in - let start = Unix.gettimeofday() in - let x = f () in - let stop = Unix.gettimeofday() in - Gc.compact (); - let mem_alloc2 = mem_allocated () in - let mem_occupied = mem_occupied x in - ignore x; - { occ=mem_occupied; - alloc=mem_alloc2-.mem_alloc1; - time=stop -. start; - } - -let spf = Printf.sprintf - -let do_test ~name f = - Format.printf "test %s...@." name; - let res = measure_time_mem f in - Format.printf " allocated:%.2f MB, occupied:%d kB, time: %.2f s@." - (res.alloc *. 8. /. 1_000_000.) - res.occ - res.time - -let test_hashtrie n = - let module M = CCHashTrie.Make(CCInt) in - do_test ~name:(spf "hashtrie(%d)" n) - (fun () -> - let m = M.of_seq Sequence.(1 -- n |> map (fun x-> x,x)) in - m - ) - -let test_hamt n = - let module M = Hamt.Make'(CCInt) in - do_test ~name:(spf "hamt(%d)" n) - (fun () -> - let m = Sequence.(1 -- n - |> map (fun x-> x,x) - |> fold (fun m (k,v) -> M.add k v m) M.empty - ) in - m - ) - -let test_map n = - let module M = CCMap.Make(CCInt) in - do_test ~name:(spf "map(%d)" n) - (fun () -> - let m = M.of_seq Sequence.(1 -- n |> map (fun x-> x,x)) in - m - ) - -let test_wbt n = - let module M = CCWBTree.Make(CCInt) in - do_test ~name:(spf "wbt(%d)" n) - (fun () -> - let m = M.of_seq Sequence.(1 -- n |> map (fun x-> x,x)) in - m - ) - -let test_hashtbl n = - let module H = CCHashtbl.Make(CCInt) in - do_test ~name:(spf "hashtbl(%d)" n) - (fun () -> - let m = H.of_seq Sequence.(1 -- n |> map (fun x-> x,x)) in - m - ) - -let test_intmap n = - let module M = CCIntMap in - do_test ~name:(spf "intmap(%d)" n) - (fun () -> - let m = M.of_seq Sequence.(1 -- n |> map (fun x-> x,x)) in - m - ) - -let tests_ = - [ "hashtrie", test_hashtrie - ; "map", test_map - ; "hamt", test_hamt - ; "wbt", test_wbt - ; "hashtbl", test_hashtbl - ; "intmap", test_intmap - ] - -let run_test ~n name = List.assoc name tests_ n - -let print_list () = - Format.printf "@[tests:@ [@[%a@]]@]@." - CCFormat.(list string) (List.map fst tests_) - -let () = - let to_test = ref [] in - let n = ref 1_000_000 in - let options = Arg.align - [ "-n", Arg.Set_int n, " size of the collection" - ] in - Arg.parse options (CCList.Ref.push to_test) "usage: mem_measure [name*]"; - match !to_test with - | [] -> - print_list (); - exit 0 - | _ -> List.iter (run_test ~n:!n) (List.rev !to_test) diff --git a/benchs/run_bench_hash.ml b/benchs/run_bench_hash.ml index 42a57025..7b5ba69e 100644 --- a/benchs/run_bench_hash.ml +++ b/benchs/run_bench_hash.ml @@ -25,15 +25,15 @@ let rec eq t1 t2 = match t1, t2 with | Node _, _ | _, Node _ -> false -let rec hash_tree t h = match t with - | Empty -> CCHash.string "empty" h +let rec hash_tree t = match t with + | Empty -> CCHash.string "empty" | Node (i, l) -> - CCHash.list hash_tree l (CCHash.int i (CCHash.string "node" h)) + CCHash.(combine2 (int i) (list hash_tree l)) module H = Hashtbl.Make(struct type t = tree let equal = eq - let hash = CCHash.apply hash_tree + let hash = hash_tree end) let print_hashcons_stats st = diff --git a/benchs/run_benchs.ml b/benchs/run_benchs.ml index d6eaa63e..9fb59a6c 100644 --- a/benchs/run_benchs.ml +++ b/benchs/run_benchs.ml @@ -558,6 +558,7 @@ module Tbl = struct end in (module T) +(* let hamt : type a. a key_type -> (module MUT with type key = a) = fun k -> let (module K), name = arg_make k in @@ -568,6 +569,7 @@ module Tbl = struct end in let module U = MUT_OF_IMMUT(T) in (module U) + *) let modules_int = [ hashtbl_make Int @@ -579,7 +581,7 @@ module Tbl = struct ; flat_hashtbl ; hashtrie Int ; hashtrie_mut Int - ; hamt Int + (* ; hamt Int *) ] let modules_string = @@ -588,7 +590,7 @@ module Tbl = struct ; wbt Str ; hashtrie Str ; persistent_hashtbl Str - ; hamt Str + (* ; hamt Str *) ; trie ] diff --git a/opam b/opam index 751f23b0..a2874818 100644 --- a/opam +++ b/opam @@ -6,11 +6,9 @@ maintainer: "simon.cruanes@inria.fr" build: [ ["./configure" "--prefix" prefix - "--%{base-threads:enable}%-thread" "--disable-bench" "--disable-tests" "--%{base-bigarray:enable}%-bigarray" - "--%{sequence:enable}%-advanced" "--%{base-unix:enable}%-unix" "--enable-docs" ] @@ -25,14 +23,19 @@ remove: [ ["ocamlfind" "remove" "containers"] ] depends: [ - "ocamlfind" {build} - "oasis" {build} - "base-bytes" - "result" - "cppo" {build} - "ocamlbuild" {build} + "ocamlfind" {build} + "oasis" {build} + "base-bytes" + "result" + "cppo" {build} + "ocamlbuild" {build} +] +depopts: [ + "base-bigarray" + "base-unix" + "base-threads" + "qtest" { test } ] -depopts: [ "sequence" "base-bigarray" "base-unix" "base-threads" "qtest" { test } ] conflicts: [ "sequence" { < "0.5" } "qtest" { < "2.2" }