mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
updated benchmarks for Cache, to use new API and fix a stupid issue
This commit is contained in:
parent
05ba0e5bba
commit
fbc278907a
1 changed files with 22 additions and 41 deletions
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue