Skip to content

Commit

Permalink
PARTIAL: introduce simple data-encoding bench
Browse files Browse the repository at this point in the history
This is mostly legwork to get familiar with the environment. A more
interesting benchmark will follow.
  • Loading branch information
raphael-proust committed May 26, 2020
1 parent 6fe4e3f commit e3a49d6
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 37 additions & 0 deletions benchmarks/data_encoding/de_basic.ml
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 7 additions & 0 deletions benchmarks/data_encoding/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(executable
(name de_basic)
(modules de_basic)
(libraries data-encoding)
)

(alias (name buildbench) (deps data_encoding_basic.exe))
16 changes: 16 additions & 0 deletions run_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}
]
}

0 comments on commit e3a49d6

Please sign in to comment.