Skip to content

Commit

Permalink
Add fields on statistics to benchmark JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
polytypic committed Jan 5, 2024
1 parent 05e04f1 commit ad3f582
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions bench/bench.ml
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,17 @@ module Stats = struct
median : float;
sd : float;
inverted : bool;
best : float;
runs : int;
}

let scale factor { mean; median; sd; inverted; runs } =
let scale factor { mean; median; sd; inverted; best; runs } =
{
mean = mean *. factor;
median = median *. factor;
sd = sd *. factor;
inverted;
best = best *. factor;
runs;
}

Expand All @@ -139,25 +141,34 @@ module Stats = struct
let mean = mean_of times in
let sd = sd_of times mean in
let median = median_of times in
{ mean; sd; median; inverted; runs }
let best =
if inverted then Array.fold_left Float.max Float.min_float times
else Array.fold_left Float.min Float.max_float times
in
{ mean; sd; median; inverted; best; runs }

let to_nonbreaking s =
s |> String.split_on_char ' '
|> String.concat " " (* a non-breaking space *)

let to_json ~name ~description ~units t =
let metric value =
let trend =
if t.inverted then `String "higher-is-better"
else `String "lower-is-better"
in
[
`Assoc
[
("name", `String (to_nonbreaking name));
("value", `Float value);
("value", `Float t.median);
("units", `String units);
( "trend",
if t.inverted then `String "higher-is-better"
else `String "lower-is-better" );
("trend", trend);
("description", `String description);
("#best", `Float t.best);
("#mean", `Float t.mean);
("#median", `Float t.median);
("#sd", `Float t.sd);
("#runs", `Int t.runs);
]
in
[ metric t.median ]
];
]
end

0 comments on commit ad3f582

Please sign in to comment.