updated benchmarks for Cache, to use new API and fix a stupid issue

This commit is contained in:
Simon Cruanes 2014-11-17 02:52:46 +01:00
parent 05ba0e5bba
commit fbc278907a

View file

@ -127,56 +127,37 @@ module Vec = struct
end end
module Cache = struct module Cache = struct
module Fibo(C : Cache.S with type key = int) = struct let make_fib c =
let fib ~size = let f = Cache.with_cache_rec c
let fib fib' n = (fun fib n -> match n with
match n with
| 0 -> 0 | 0 -> 0
| 1 -> 1 | 1 -> 1
| 2 -> 1 | 2 -> 1
| n -> | n -> fib (n-1) + fib (n-2)
fib' (n-1) + fib' (n-2) )
in in
let cache = C.create size in fun x ->
let cached_fib x = C.with_cache_rec cache fib x in Cache.clear c;
cached_fib f x
end
module LinearIntCache = Cache.Linear(struct
type t = int
let equal i j = i = j
end)
module ReplacingIntCache = Cache.Replacing(struct
type t = int
let equal i j = i = j
let hash i = i
end)
module LRUIntCache = Cache.LRU(struct
type t = int
let equal i j = i = j
let hash i = i
end)
module DummyIntCache = Cache.Dummy(struct type t = int end)
module LinearFibo = Fibo(LinearIntCache)
module ReplacingFibo = Fibo(ReplacingIntCache)
module LRUFibo= Fibo(LRUIntCache)
module DummyFibo = Fibo(DummyIntCache)
let bench_fib n = let bench_fib n =
CCBench.throughputN 3 let l =
[ "linear_fib", LinearFibo.fib ~size:5, n; [ "replacing_fib", make_fib (Cache.replacing 256), n
"replacing_fib", ReplacingFibo.fib ~size:256, n; ; "LRU_fib", make_fib (Cache.lru 256), n
"LRU_fib", LRUFibo.fib ~size:256, n;
"dummy_fib", DummyFibo.fib ~size:5, n;
] ]
in
let l = if n <= 20
then [ "linear_fib (5)", make_fib (Cache.linear 5), n
; "linear_fib (32)", make_fib (Cache.linear 32), n
; "dummy_fib", make_fib Cache.dummy, n
] @ l
else l
in
CCBench.throughputN 3 l
let () = CCBench.register CCBench.( let () = CCBench.register CCBench.(
"cache" >::: "cache" >:::
[ "fib" >:: with_int bench_fib [10; 100] [ "fib" >:: with_int bench_fib [10; 20; 100; 200; 1_000;]
] ]
) )
end end