Skip to content

Commit

Permalink
add urandom-channel to the benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesm committed Oct 29, 2024
1 parent 9eff386 commit 53da5fb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bench/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(names speed)
(modules speed)
(libraries mirage-crypto mirage-crypto-rng mirage-crypto-rng.unix
mirage-crypto-pk mirage-crypto-ec mirage-crypto-rng-miou-unix))
mirage-crypto-pk mirage-crypto-ec mirage-crypto-rng-miou-unix threads.posix))

; marking as "(optional)" leads to OCaml-CI failures
; marking with "(package mirage-crypto-rng-miou-unix)" only has an effect with a "public_name"
Expand Down
9 changes: 9 additions & 0 deletions bench/speed.ml
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,15 @@ let benchmarks = [
throughput name (fun buf ->
let buf = Bytes.unsafe_of_string buf in
Mirage_crypto_rng_unix.getrandom_into buf ~off:0 ~len:(Bytes.length buf))) ;

bm "urandom-channel" (fun name ->
In_channel.with_open_bin "/dev/urandom" @@ fun ic ->
let m = Mutex.create () in
let finally () = Mutex.unlock m in
throughput name (fun buf ->
let buf = Bytes.unsafe_of_string buf in
Mutex.lock m;
Fun.protect ~finally (fun () -> really_input ic buf 0 (Bytes.length buf))));
]

let help () =
Expand Down

0 comments on commit 53da5fb

Please sign in to comment.