mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
small benchmarking of hashtable
This commit is contained in:
parent
723e4f1905
commit
17ae421266
2 changed files with 51 additions and 0 deletions
3
Makefile
3
Makefile
|
|
@ -11,6 +11,9 @@ all:
|
|||
tests:
|
||||
ocamlbuild $(OPTIONS) -package oUnit -I . tests/tests.native
|
||||
|
||||
bench:
|
||||
ocamlbuild $(OPTIONS) -package bench -package unix -I . tests/benchs.native
|
||||
|
||||
clean:
|
||||
ocamlbuild -clean
|
||||
|
||||
|
|
|
|||
48
tests/benchs.ml
Normal file
48
tests/benchs.ml
Normal 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
|
||||
Loading…
Add table
Reference in a new issue