update mem_measure with optional size argument

This commit is contained in:
Simon Cruanes 2015-09-19 14:35:06 +02:00
parent 359740a587
commit 2179e394fb

View file

@ -39,7 +39,7 @@ let do_test ~name f =
res.occ res.occ
res.time res.time
let test_hashtrie n () = let test_hashtrie n =
let module M = CCHashTrie.Make(CCInt) in let module M = CCHashTrie.Make(CCInt) in
do_test ~name:(spf "hashtrie(%d)" n) do_test ~name:(spf "hashtrie(%d)" n)
(fun () -> (fun () ->
@ -47,7 +47,7 @@ let test_hashtrie n () =
m m
) )
let test_hamt n () = let test_hamt n =
let module M = Hamt.Make'(CCInt) in let module M = Hamt.Make'(CCInt) in
do_test ~name:(spf "hamt(%d)" n) do_test ~name:(spf "hamt(%d)" n)
(fun () -> (fun () ->
@ -58,7 +58,7 @@ let test_hamt n () =
m m
) )
let test_map n () = let test_map n =
let module M = CCMap.Make(CCInt) in let module M = CCMap.Make(CCInt) in
do_test ~name:(spf "map(%d)" n) do_test ~name:(spf "map(%d)" n)
(fun () -> (fun () ->
@ -66,7 +66,7 @@ let test_map n () =
m m
) )
let test_wbt n () = let test_wbt n =
let module M = CCWBTree.Make(CCInt) in let module M = CCWBTree.Make(CCInt) in
do_test ~name:(spf "wbt(%d)" n) do_test ~name:(spf "wbt(%d)" n)
(fun () -> (fun () ->
@ -74,7 +74,7 @@ let test_wbt n () =
m m
) )
let test_hashtbl n () = let test_hashtbl n =
let module H = CCHashtbl.Make(CCInt) in let module H = CCHashtbl.Make(CCInt) in
do_test ~name:(spf "hashtbl(%d)" n) do_test ~name:(spf "hashtbl(%d)" n)
(fun () -> (fun () ->
@ -82,18 +82,24 @@ let test_hashtbl n () =
m m
) )
let tests_ = let test_intmap n =
CCList.flat_map let module M = CCIntMap in
(fun n -> do_test ~name:(spf "intmap(%d)" n)
[ spf "hashtrie_%d" n, test_hashtrie n (fun () ->
; spf "map_%d" n, test_map n let m = M.of_seq Sequence.(1 -- n |> map (fun x-> x,x)) in
; spf "hamt_%d" n, test_hamt n m
; spf "wbt_%d" n, test_wbt n )
; spf "hashtbl_%d" n, test_hashtbl n
]
) [ 1_000; 100_000; 30_000_000 ]
let run_test name = List.assoc name tests_ () 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 () = let print_list () =
Format.printf "@[<v2>tests:@ %a@]@." Format.printf "@[<v2>tests:@ %a@]@."
@ -101,12 +107,13 @@ let print_list () =
let () = let () =
let to_test = ref [] in let to_test = ref [] in
let n = ref 1_000_000 in
let options = Arg.align let options = Arg.align
[ [ "-n", Arg.Set_int n, " size of the collection"
] in ] in
Arg.parse options (CCList.Ref.push to_test) "usage: mem_measure [name*]"; Arg.parse options (CCList.Ref.push to_test) "usage: mem_measure [name*]";
match !to_test with match !to_test with
| [] -> | [] ->
print_list (); print_list ();
exit 0 exit 0
| _ -> List.iter run_test (List.rev !to_test) | _ -> List.iter (run_test ~n:!n) (List.rev !to_test)