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 File.stat benchmark #616

Merged
merged 1 commit into from
Sep 20, 2023
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
26 changes: 26 additions & 0 deletions bench/bench_fstat.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
open Eio.Std

let ( / ) = Eio.Path.( / )

let n_stat = 100000

let run_fiber file =
for _ = 1 to n_stat do
let info = (Eio.File.stat file).kind in
assert (info = `Regular_file)
done

let run env =
Eio.Path.with_open_out ~create:(`If_missing 0o600) (env#cwd / "test-stat") @@ fun file ->
[1; 10] |> List.map (fun par ->
let t0 = Unix.gettimeofday () in
Switch.run (fun sw ->
for _ = 1 to par do
Fiber.fork ~sw (fun () -> run_fiber file)
done
);
let t1 = Unix.gettimeofday () in
let stat_per_s = float (n_stat * par) /. (t1 -. t0) in
let label = Printf.sprintf "n=%d fibers=%d" n_stat par in
Metric.create label (`Float stat_per_s) "stat/s" "Call fstat on an open file"
)
1 change: 1 addition & 0 deletions bench/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ let benchmarks = [
"Stream", Bench_stream.run;
"HTTP", Bench_http.run;
"Eio_unix.Fd", Bench_fd.run;
"File.stat", Bench_fstat.run;
]

let usage_error () =
Expand Down
Loading