From e3a49d620dcb599e38d0704d1057caf1633a5b92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Proust?= Date: Wed, 20 May 2020 12:26:20 +0100 Subject: [PATCH] PARTIAL: introduce simple data-encoding bench This is mostly legwork to get familiar with the environment. A more interesting benchmark will follow. --- Makefile | 2 +- benchmarks/data_encoding/de_basic.ml | 37 ++++++++++++++++++++++++++++ benchmarks/data_encoding/dune | 7 ++++++ run_config.json | 16 ++++++++++++ 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 benchmarks/data_encoding/de_basic.ml create mode 100644 benchmarks/data_encoding/dune diff --git a/Makefile b/Makefile index 6b0d931a9a..9cb1e724b9 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,7 @@ WRAPPER = $(subst run_,,$(RUN_BENCH_TARGET)) PACKAGES = \ cpdf menhir minilight camlimages yojson lwt alt-ergo zarith \ js_of_ocaml-compiler uuidm react ocplib-endian nbcodec checkseum decompress \ - sexplib0 irmin-mem + sexplib0 irmin-mem data-encoding DEPENDENCIES = libgmp-dev libdw-dev jq python3-pip # Ubuntu PIP_DEPENDENCIES = intervaltree diff --git a/benchmarks/data_encoding/de_basic.ml b/benchmarks/data_encoding/de_basic.ml new file mode 100644 index 0000000000..9cd4bed66a --- /dev/null +++ b/benchmarks/data_encoding/de_basic.ml @@ -0,0 +1,37 @@ +let seed = int_of_string Sys.argv.(1) +let width = int_of_string Sys.argv.(2) +let depth = int_of_string Sys.argv.(3) + +let prng = Random.State.make [| seed |] + +type box = {a: int64; b: int32;} +let box_e = + let open Data_encoding in + obj2 + (req "sixty-four" int64) + (req "thirty-two" int32) + +let box () = { + a = Random.State.int64 prng Int64.max_int; + b = Random.State.int32 prng Int32.max_int; +} +let option f () = if Random.State.bool prng then Some (f ()) else None +let rec list n f acc = + if n <= 0 then + acc + else + list (n - 1) f (f () :: acc) +let list n f () = list n f [] + +let t () = list depth (list width (option box)) () + +type t = box option list list +let e = + let open Data_encoding in + list (dynamic_size @@ list (dynamic_size option box_e)) + +let () = + let v = t () in + let b = Data_encoding.Binary.to_bytes_exn e v in + let vv = Data_encoding.Binary.of_bytes_exn e b in + assert (v = vv) diff --git a/benchmarks/data_encoding/dune b/benchmarks/data_encoding/dune new file mode 100644 index 0000000000..fb050bf25c --- /dev/null +++ b/benchmarks/data_encoding/dune @@ -0,0 +1,7 @@ +(executable + (name de_basic) + (modules de_basic) + (libraries data-encoding) +) + +(alias (name buildbench) (deps data_encoding_basic.exe)) diff --git a/run_config.json b/run_config.json index 9889030a21..d22d6d4560 100644 --- a/run_config.json +++ b/run_config.json @@ -1137,6 +1137,22 @@ "params": "" } ] + }, + { + "executable": "benchmarks/data_encoding/de_basic.exe", + "name": "data_encoding_basic", + "ismacrobench": true, + "runs": [ + { + "params": "100 100" + }, + { + "params": "100000 100" + }, + { + "params": "100 100000" + } + ] } ] }