1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
let delim = Str.regexp_string "│"
let geometric_mean l =
exp (List.fold_left ( +. ) 0. (List.map log l) /. float (List.length l))
let parse s =
Scanf.sscanf (String.trim s) "%f%s"
@@ fun f u ->
match u with
| "ns" -> f *. 1e-6
| "us" -> f *. 1e-3
| "ms" -> f
| "s" -> f *. 1e3
| _ -> assert false
let () =
let measures = ref [] in
(try
while true do
let l = read_line () in
if String.starts_with ~prefix:"├" l
then
let l = read_line () |> Str.split delim |> List.tl |> List.map parse in
measures := l @ !measures
done
with End_of_file -> ());
Format.printf
{|{ "name": "%s",
"results":
[ { "name": "Partial Render Table",
"metrics":
[ { "name": "Execution time (geometric mean)",
"units": "ms",
"value": %f } ] } ] }@.|}
(String.capitalize_ascii Sys.argv.(1))
(geometric_mean !measures)
|