updated benchmark

This commit is contained in:
Simon Cruanes 2013-03-05 00:55:24 +01:00
parent deab8c8f62
commit f3074584ff
2 changed files with 5 additions and 10 deletions

View file

@ -92,7 +92,6 @@ let insert t key value =
t.buckets.(j) <- Used (key, value, dist) t.buckets.(j) <- Used (key, value, dist)
| Used (key', _, _) when t.eq key key' -> | Used (key', _, _) when t.eq key key' ->
(* insert here (erase old value) *) (* insert here (erase old value) *)
t.size <- t.size + 1;
t.buckets.(j) <- Used (key, value, dist) t.buckets.(j) <- Used (key, value, dist)
| Used (key', value', dist') when dist > dist' -> | Used (key', value', dist') when dist > dist' ->
(* displace this key/value *) (* displace this key/value *)
@ -108,7 +107,7 @@ let insert t key value =
(** Resize the array, by inserting its content into twice as large an array *) (** Resize the array, by inserting its content into twice as large an array *)
let resize t = let resize t =
let new_size = min (Array.length t.buckets * 2 + 1) Sys.max_array_length in let new_size = min (Array.length t.buckets * 2 + 1) Sys.max_array_length in
assert (new_size > Array.length t.buckets); if not (new_size > Array.length t.buckets) then failwith "hashtbl is full";
let old_buckets = t.buckets in let old_buckets = t.buckets in
t.buckets <- Array.make new_size Empty; t.buckets <- Array.make new_size Empty;
t.size <- 0; (* will be updated again *) t.size <- 0; (* will be updated again *)

View file

@ -16,11 +16,9 @@ let hashtbl_add n =
h h
let _ = let _ =
let n = 50000 in let res = Bench.bench_n
let res = Bench.bench_funs
["phashtbl_add", (fun n -> ignore (phashtbl_add n)); ["phashtbl_add", (fun n -> ignore (phashtbl_add n));
"hashtbl_add", (fun n -> ignore (hashtbl_add n));] "hashtbl_add", (fun n -> ignore (hashtbl_add n));]
n
in in
Bench.summarize 1. res Bench.summarize 1. res
@ -29,7 +27,7 @@ let phashtbl_replace n =
for i = 0 to n do for i = 0 to n do
PHashtbl.replace h i i; PHashtbl.replace h i i;
done; done;
for i = 0 to n do for i = n downto 0 do
PHashtbl.replace h i i; PHashtbl.replace h i i;
done; done;
h h
@ -39,17 +37,15 @@ let hashtbl_replace n =
for i = 0 to n do for i = 0 to n do
Hashtbl.replace h i i; Hashtbl.replace h i i;
done; done;
for i = 0 to n do for i = n downto 0 do
Hashtbl.replace h i i; Hashtbl.replace h i i;
done; done;
h h
let _ = let _ =
let n = 50000 in let res = Bench.bench_n
let res = Bench.bench_funs
["phashtbl_replace", (fun n -> ignore (phashtbl_replace n)); ["phashtbl_replace", (fun n -> ignore (phashtbl_replace n));
"hashtbl_replace", (fun n -> ignore (hashtbl_replace n));] "hashtbl_replace", (fun n -> ignore (hashtbl_replace n));]
n
in in
Bench.summarize 1. res Bench.summarize 1. res