-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PARTIAL: introduce simple data-encoding bench
This is mostly legwork to get familiar with the environment. A more interesting benchmark will follow.
- Loading branch information
1 parent
6fe4e3f
commit e3a49d6
Showing
4 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters