Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for running microbenchmarks on supported bitgenerators #11

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
Loading