small benchmarking of hashtable

This commit is contained in:
Simon Cruanes 2013-03-04 14:58:23 +01:00
parent 723e4f1905
commit 17ae421266
2 changed files with 51 additions and 0 deletions

View file

@ -11,6 +11,9 @@ all:
tests: tests:
ocamlbuild $(OPTIONS) -package oUnit -I . tests/tests.native ocamlbuild $(OPTIONS) -package oUnit -I . tests/tests.native
bench:
ocamlbuild $(OPTIONS) -package bench -package unix -I . tests/benchs.native
clean: clean:
ocamlbuild -clean ocamlbuild -clean

48
tests/benchs.ml Normal file
View file

@ -0,0 +1,48 @@
(** Benchmarking *)
let phashtbl_add n =
let h = PHashtbl.create 50 in
for i = 0 to n do
PHashtbl.add h i i;
done;
h
let hashtbl_add n =
let h = Hashtbl.create 50 in
for i = 0 to n do
Hashtbl.add h i i;
done;
h
let _ =
let n = 50000 in
let res = Bench.bench_funs
["phashtbl_add", (fun n -> ignore (phashtbl_add n));
"hashtbl_add", (fun n -> ignore (hashtbl_add n));]
n
in
Bench.summarize 1. res
let phashtbl_mem h =
fun n ->
for i = 0 to n do
ignore (PHashtbl.find h i);
done
let hashtbl_mem h =
fun n ->
for i = 0 to n do
ignore (Hashtbl.find h i);
done
let _ =
let n = 50000 in
let h = phashtbl_add n in
let h' = hashtbl_add n in
let res = Bench.bench_funs
["phashtbl_mem", phashtbl_mem h;
"hashtbl_mem", hashtbl_mem h';]
n
in
Bench.summarize 1. res