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 27, 2020
1 parent 6fe4e3f commit cee8eeb
Show file tree
Hide file tree
Showing 8 changed files with 182 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))
30 changes: 30 additions & 0 deletions dependencies/packages/data-encoding/data-encoding.0.2/opam
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
opam-version: "2.0"
maintainer: "[email protected]"
authors: [ "Nomadic Labs" ]
homepage: "https://gitlab.com/nomadic-labs/data-encoding"
bug-reports: "https://gitlab.com/nomadic-labs/data-encoding/issues"
dev-repo: "git+https://gitlab.com/nomadic-labs/data-encoding.git"
license: "MIT"
depends: [
"ocaml" { >= "4.07" }
"dune" { >= "1.7" }
"ezjsonm"
"zarith"
"json-data-encoding" { = "0.8" }
"json-data-encoding-bson" { = "0.8" }
"alcotest" { with-test }
"crowbar" { with-test }
]
build: [
["dune" "build" "-p" name "-j" jobs]
["dune" "runtest" "-p" name "-j" jobs] {with-test}
]
synopsis: "Library of JSON and binary encoding combinators"
url {
src:
"https://gitlab.com/nomadic-labs/data-encoding/-/archive/0.2/data-encoding-0.2.tar.gz"
checksum: [
"md5=c3573f2f066f61437feb6d33d476ee09"
"sha512=d9b95c0b4655930d590a78288edad50fbb845dfff1d2378c11e7f7b2499a70380af2edf289f24145f58c92091195f8326bf51efdb980cd221c22357f9919c37c"
]
}
36 changes: 36 additions & 0 deletions dependencies/packages/ezjsonm/ezjsonm.1.1.0/opam
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
opam-version: "2.0"
maintainer: "[email protected]"
authors: "Thomas Gazagnaire"
license: "ISC"
tags: ["org:mirage" "org:ocamllabs"]
homepage: "https://github.com/mirage/ezjsonm"
doc: "https://mirage.github.io/ezjsonm/"
bug-reports: "https://github.com/mirage/ezjsonm/issues"
depends: [
"ocaml" {>="4.03.0"}
"dune" {>= "1.0"}
"alcotest" {with-test & >= "0.4.0"}
"jsonm" {>= "1.0.0"}
"sexplib" {< "v0.14"}
"hex"
]
build: [
["dune" "subst"] {pinned}
["dune" "build" "-p" name "-j" jobs]
]
dev-repo: "git+https://github.com/mirage/ezjsonm.git"
synopsis: "Simple interface on top of the Jsonm JSON library"
description: """
Ezjsonm provides more convenient (but far less flexible)
input and output functions that go to and from `string` values.
This avoids the need to write signal code, which is useful for
quick scripts that manipulate JSON.

More advanced users should go straight to the Jsonm library and
use it directly, rather than be saddled with the Ezjsonm interface.
"""
url {
src:
"https://github.com/mirage/ezjsonm/releases/download/v1.1.0/ezjsonm-v1.1.0.tbz"
checksum: "md5=e8f207c6cd2226b2c4784b1e56556797"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
opam-version: "2.0"
synopsis: "Type-safe encoding to and decoding from JSON (bson support)"
maintainer: "[email protected]"
authors: [ "Nomadic Labs" "Ocamlpro" ]
homepage: "https://gitlab.com/nomadic-labs/json-data-encoding"
bug-reports: "https://gitlab.com/nomadic-labs/json-data-encoding/issues"
license: "LGPLv3 w/ linking exception"
dev-repo: "git+https://gitlab.com/nomadic-labs/json-data-encoding"

build: [
["dune" "build" "-j" jobs "-p" name]
]

depends: [
"ocaml" {>= "4.03.0"}
"dune" {>= "1.7"}
"json-data-encoding" {= version }
"ocplib-endian" {>= "1.0"}
]
url {
src:
"https://gitlab.com/nomadic-labs/json-data-encoding/-/archive/v0.8/json-data-encoding-v0.8.tar.gz"
checksum: [
"md5=24fcb7feb10395eaaf840d1f8ccf162f"
"sha512=f6d2a00008a0cd88bfae2458f56dde8f45c4e209ece9805d3e8d2c74401e4a5f9e12f99d5318f58a30a4579d9c9e9f204a75269c2110bb16a3e1036b2599b7a5"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
opam-version: "2.0"
synopsis: "Type-safe encoding to and decoding from JSON"
maintainer: "[email protected]"
authors: [ "Nomadic Labs" "Ocamlpro" ]
homepage: "https://gitlab.com/nomadic-labs/json-data-encoding"
bug-reports: "https://gitlab.com/nomadic-labs/json-data-encoding/issues"
license: "LGPLv3 w/ linking exception"
dev-repo: "git+https://gitlab.com/nomadic-labs/json-data-encoding"

build: [
["dune" "build" "-j" jobs "-p" name]
["dune" "runtest" "-p" name "-j" jobs] {with-test}
]

depends: [
"ocaml" {>= "4.03.0"}
"dune" {>= "1.7"}
"uri" {>= "1.9.0" }
"crowbar" { with-test }
]
url {
src:
"https://gitlab.com/nomadic-labs/json-data-encoding/-/archive/v0.8/json-data-encoding-v0.8.tar.gz"
checksum: [
"md5=24fcb7feb10395eaaf840d1f8ccf162f"
"sha512=f6d2a00008a0cd88bfae2458f56dde8f45c4e209ece9805d3e8d2c74401e4a5f9e12f99d5318f58a30a4579d9c9e9f204a75269c2110bb16a3e1036b2599b7a5"
]
}
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 cee8eeb

Please sign in to comment.