@@ -12,38 +12,55 @@ let print_brief json =
12
12
Printf. printf " %s:\n " metric.name;
13
13
Printf. printf " %.2f %s\n " metric.value metric.units
14
14
15
+ let worse_colors = [| 196 ; 197 ; 198 ; 199 ; 200 ; 201 |]
16
+ let better_colors = [| 46 ; 47 ; 48 ; 49 ; 50 ; 51 |]
17
+
15
18
let print_diff base next =
16
19
let open Data in
17
20
Option. pair (Results. parse base) (Results. parse next)
18
21
|> Option. iter @@ fun (base , next ) ->
19
22
List. zip_by Benchmark. compare_by_name base next
20
23
|> List. iter @@ fun ((base : Benchmark.t ), (next : Benchmark.t )) ->
21
24
Printf. printf " %s:\n " base.name;
22
- List. zip_by Metric. compare_by_name base.metrics next.metrics
25
+ let zipped =
26
+ List. zip_by Metric. compare_by_name base.metrics next.metrics
27
+ in
28
+ let extreme_of join trend =
29
+ List. fold_left
30
+ (fun acc ((base : Metric.t ), (next : Metric.t )) ->
31
+ if trend <> base.trend || trend <> next.trend then acc
32
+ else join acc (next.value /. base.value))
33
+ 1.0 zipped
34
+ in
35
+ let min_higher = extreme_of Float. min `Higher_is_better in
36
+ let max_higher = extreme_of Float. max `Higher_is_better in
37
+ let min_lower = extreme_of Float. min `Lower_is_better in
38
+ let max_lower = extreme_of Float. max `Lower_is_better in
39
+ zipped
23
40
|> List. iter @@ fun ((base : Metric.t ), (next : Metric.t )) ->
24
41
Printf. printf " %s:\n " base.name;
25
42
if base.trend <> next.trend || base.units <> next.units then
26
43
Printf. printf " %.2f %s\n " next.value next.units
27
44
else
28
45
let times = next.value /. base.value in
29
- if
30
- ( next.trend = `Higher_is_better && times < 0.95 )
31
- || (next.trend = `Lower_is_better && 1.05 < times )
32
- then
33
- Printf. printf
34
- " %.2f %s = \x1b [1;31m%.2f \x1b\x1b [0;39;49m x %.2f %s \n "
35
- next.value next.units times base.value base.units
36
- else if
37
- (next.trend = `Higher_is_better && 1.05 < times)
38
- || (next.trend = `Lower_is_better && times < 0.95 )
39
- then
40
- Printf. printf
41
- " %.2f %s = \x1b [1;32m%.2f \x1b\x1b [0;39;49m x %.2f %s \n "
42
- next.value next.units times base.value base.units
43
- else
44
- Printf. printf
45
- " %.2f %s = \x1b [1;33m %.2f\x1b\x1b [0;39;49m x %.2f %s\n "
46
- next.value next.units times base.value base.units
46
+ let colors, extreme =
47
+ if next.trend = `Higher_is_better then
48
+ if times < 1.0 then (worse_colors, min_higher )
49
+ else (better_colors, max_higher)
50
+ else if 1.0 < times then (worse_colors, max_lower)
51
+ else (better_colors, min_lower)
52
+ in
53
+ let range = Float. abs (extreme -. 1.0 ) in
54
+ let color =
55
+ colors.( Float. to_int
56
+ ( Float. round
57
+ ( Float. of_int ( Array. length colors - 1 )
58
+ *. Float. abs (extreme -. times)
59
+ /. range)))
60
+ in
61
+ Printf. printf
62
+ " %.2f %s = \x1b [1;38;5;%dm %.2f\x1b\x1b [0;39;49m x %.2f %s\n "
63
+ next.value next.units color times base.value base.units
47
64
48
65
let run_benchmark ~budgetf ~debug (name , fn ) =
49
66
if debug then
0 commit comments