Skip to content

Commit

Permalink
Add support for running microbenchmarks on supported bitgenerators
Browse files Browse the repository at this point in the history
  • Loading branch information
Pass Automated Testing Suite authored and zoj613 committed Apr 18, 2024
1 parent 3b5f8d4 commit c67aabc
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ jobs:
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

- name: Run microbenchmarks
run: |
opam install testu01 core_bench core_unix --yes
opam exec -- dune build bin
opam exec -- dune exec -- bench
- name: Build Docs
run: opam exec -- dune build @doc

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ $ dune exec -- crush pcg64

All tests were passed
```
## Benchmarks
A utility to compare the performance of each bitgenerator's `next_uint64` function is provided.
To compile the benchmark executor run `dune build bin`, and then run it using `dune exec -- bench`.
Once the benchmark run has completed, a summary table will be displayed in stdout.


[1]: https://codecov.io/gh/zoj613/bitgenerators/graph/badge.svg?token=KOOG2Y1SH5
Expand Down
36 changes: 36 additions & 0 deletions bin/bench.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
open Bitgen

module type S = sig
type t
val next_uint64 : t -> Stdint.uint64 * t
val initialize : SeedSequence.t -> t
end


let make_bits (module M : S) =
let ss = SeedSequence.initialize [Stdint.Uint128.of_int 123456789] in
let t = ref (M.initialize ss) in
let bits () = match M.next_uint64 !t with
| (u, t') -> t := t'; u
in
bits


let pairs = [
"PCG64", (module PCG64: S);
"SFC64", (module SFC64: S);
"Xoshiro256", (module Xoshiro256: S);
"Philox64", (module Philox64: S);
]


let make_fn (name, m) =
Core_bench.Bench.Test.create ~name:(name ^ ".next_uint64") (make_bits m)


let () =
Stdlib.Random.init 123456789;
[Core_bench.Bench.Test.create ~name:"Stdlib.Random.bits64" (fun () -> Stdlib.Random.int64 Int64.max_int)] @
List.map make_fn pairs
|> Core_bench.Bench.make_command
|> Command_unix.run
9 changes: 8 additions & 1 deletion bin/dune
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
(executable
(public_name crush)
(name crush)
(modules crush)
(ocamlopt_flags (:standard -O3))
(libraries bitgenerators testu01))


(executable
(public_name bench)
(modules bench)
(ocamlopt_flags (:standard -O3))
(libraries bitgenerators core_bench core_unix.command_unix))

0 comments on commit c67aabc

Please sign in to comment.