Commit 40a8ae44 authored by POTTIER Francois's avatar POTTIER Francois

Add a first mini-benchmark.

parent 9ec30d69
PKG visitors.ppx
PKG visitors.runtime
PKG hashcons
PKG core_bench
B _build
......@@ -14,17 +14,20 @@ OCAMLBUILD := \
-classic-display \
-cflags "-g" -lflags "-g" \
.PHONY: test mli processed clean
.PHONY: test bench mli processed clean
test:
@ make -C ../src uninstall || true
@ make -C ../src install
@ make -C ../src reinstall
@ $(OCAMLBUILD) $(TARGETS)
# @ for i in $(TARGET) ; do echo "Running $$i..." && ./$$i ; done
bench:
@ make -C ../src reinstall
@ $(OCAMLBUILD) bench.native
@ ./bench.native
mli:
@ make -C ../src uninstall || true
@ make -C ../src install
@ make -C ../src reinstall
@ $(OCAMLBUILD) $(MLI)
@ more $(patsubst %,_build/%,$(MLI))
......
......@@ -6,3 +6,7 @@ true: \
<expr07*> or <expr08*> or <expr14*>: \
package(hashcons)
<bench.*>: \
thread, \
package(core_bench)
type expr =
| EConst of int
| EAdd of expr * expr
[@@deriving visitors { variety = "iter"; concrete = true },
visitors { variety = "map"; concrete = true }]
let rec native_iter env e =
match e with
| EConst _ ->
()
| EAdd (e1, e2) ->
native_iter env e1;
native_iter env e2
let split n =
assert (n >= 0);
let n1 = Random.int (n + 1) in
let n2 = n - n1 in
assert (0 <= n1 && n1 <= n);
assert (0 <= n2 && n2 <= n);
n1, n2
let rec generate n =
assert (n >= 0);
if n = 0 then
EConst (Random.int 100)
else
let n1, n2 = split (n - 1) in
EAdd (generate n1, generate n2)
let rec list_init i n f =
if i = n then
[]
else
let x = f i in
x :: list_init (i + 1) n f
let list_init n f =
list_init 0 n f
let samples =
list_init 100 (fun _ -> generate 100)
let iter : expr -> unit =
new iter # visit_expr ()
let test f () =
List.iter f samples
let tests = [
"iter", test iter;
"native_iter", test (native_iter ());
]
module Bench = Core_bench.Std.Bench
module Command = Core.Std.Command
let tests =
List.map (fun (name, test) -> Bench.Test.create ~name test) tests
let () =
Command.run (Bench.make_command tests)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment