mirror of
https://github.com/ocaml-tracing/ocaml-trace.git
synced 2026-03-07 18:37:56 -05:00
fix bench
This commit is contained in:
parent
d7f0aff406
commit
c3bd2f92a8
2 changed files with 39 additions and 30 deletions
|
|
@ -1,23 +1,34 @@
|
|||
open Trace_fuchsia_write
|
||||
open Trace_fuchsia
|
||||
open Trace_fuchsia.Writer
|
||||
module B = Benchmark
|
||||
|
||||
let pf = Printf.printf
|
||||
|
||||
let encode_1_span (out : Output.t) () =
|
||||
Event.Duration_complete.encode out ~name:"span" ~t_ref:(Thread_ref.Ref 5)
|
||||
let encode_1000_span (bufs : Buf_chain.t) () =
|
||||
for _i = 1 to 1000 do
|
||||
Event.Duration_complete.encode bufs ~name:"span" ~t_ref:(Thread_ref.Ref 5)
|
||||
~time_ns:100_000L ~end_time_ns:5_000_000L ~args:[] ()
|
||||
|
||||
let encode_3_span (out : Output.t) () =
|
||||
Event.Duration_complete.encode out ~name:"outer" ~t_ref:(Thread_ref.Ref 5)
|
||||
~time_ns:100_000L ~end_time_ns:5_000_000L ~args:[] ();
|
||||
Event.Duration_complete.encode out ~name:"inner" ~t_ref:(Thread_ref.Ref 5)
|
||||
~time_ns:180_000L ~end_time_ns:4_500_000L ~args:[] ();
|
||||
Event.Instant.encode out ~name:"hello" ~time_ns:1_234_567L
|
||||
~t_ref:(Thread_ref.Ref 5)
|
||||
~args:[ "x", `Int 42 ]
|
||||
done;
|
||||
Buf_chain.ready_all_non_empty bufs;
|
||||
Buf_chain.pop_ready bufs ~f:ignore;
|
||||
()
|
||||
|
||||
let time_per_iter_ns (samples : B.t list) : float =
|
||||
let encode_300_span (bufs : Buf_chain.t) () =
|
||||
for _i = 1 to 100 do
|
||||
Event.Duration_complete.encode bufs ~name:"outer" ~t_ref:(Thread_ref.Ref 5)
|
||||
~time_ns:100_000L ~end_time_ns:5_000_000L ~args:[] ();
|
||||
Event.Duration_complete.encode bufs ~name:"inner" ~t_ref:(Thread_ref.Ref 5)
|
||||
~time_ns:180_000L ~end_time_ns:4_500_000L ~args:[] ();
|
||||
Event.Instant.encode bufs ~name:"hello" ~time_ns:1_234_567L
|
||||
~t_ref:(Thread_ref.Ref 5)
|
||||
~args:[ "x", A_int 42 ]
|
||||
()
|
||||
done;
|
||||
Buf_chain.ready_all_non_empty bufs;
|
||||
Buf_chain.pop_ready bufs ~f:ignore;
|
||||
()
|
||||
|
||||
let time_per_iter_ns n_per_iter (samples : B.t list) : float =
|
||||
let n_iters = ref 0L in
|
||||
let time = ref 0. in
|
||||
List.iter
|
||||
|
|
@ -25,34 +36,32 @@ let time_per_iter_ns (samples : B.t list) : float =
|
|||
n_iters := Int64.add !n_iters s.iters;
|
||||
time := !time +. s.stime +. s.utime)
|
||||
samples;
|
||||
!time *. 1e9 /. Int64.to_float !n_iters
|
||||
!time *. 1e9 /. (Int64.to_float !n_iters *. float n_per_iter)
|
||||
|
||||
let () =
|
||||
let buf_pool = Buf_pool.create () in
|
||||
let out =
|
||||
Output.create ~buf_pool
|
||||
~send_buf:(fun buf -> Buf_pool.recycle buf_pool buf)
|
||||
()
|
||||
in
|
||||
let bufs = Buf_chain.create ~sharded:false ~buf_pool () in
|
||||
|
||||
let samples = B.throughput1 4 ~name:"encode_1_span" (encode_1_span out) () in
|
||||
let samples =
|
||||
B.throughput1 4 ~name:"encode_1000_span" (encode_1000_span bufs) ()
|
||||
in
|
||||
B.print_gc samples;
|
||||
|
||||
let [ (_, samples) ] = samples [@@warning "-8"] in
|
||||
|
||||
let iter_per_ns = time_per_iter_ns samples in
|
||||
let iter_per_ns = time_per_iter_ns 1000 samples in
|
||||
pf "%.3f ns/iter\n" iter_per_ns;
|
||||
|
||||
()
|
||||
|
||||
let () =
|
||||
let buf_pool = Buf_pool.create () in
|
||||
let out =
|
||||
Output.create ~buf_pool
|
||||
~send_buf:(fun buf -> Buf_pool.recycle buf_pool buf)
|
||||
()
|
||||
let bufs = Buf_chain.create ~sharded:false ~buf_pool () in
|
||||
let samples =
|
||||
B.throughput1 4 ~name:"encode_300_span" (encode_300_span bufs) ()
|
||||
in
|
||||
|
||||
let samples = B.throughput1 4 ~name:"encode_3_span" (encode_3_span out) () in
|
||||
B.print_gc samples;
|
||||
|
||||
let [ (_, samples) ] = samples [@@warning "-8"] in
|
||||
let iter_per_ns = time_per_iter_ns 300 samples in
|
||||
pf "%.3f ns/iter\n" iter_per_ns;
|
||||
()
|
||||
|
|
|
|||
|
|
@ -20,4 +20,4 @@
|
|||
(executable
|
||||
(name bench_fuchsia_write)
|
||||
(modules bench_fuchsia_write)
|
||||
(libraries benchmark trace-fuchsia.write))
|
||||
(libraries benchmark trace-fuchsia))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue