@@ -17,41 +17,30 @@ import SwiftUI
17
17
struct BenchmarkChart : View {
18
18
var comparisons : [ BenchmarkResult . Comparison ]
19
19
20
+ var sortedComparisons : [ BenchmarkResult . Comparison ] {
21
+ comparisons. sorted { a, b in
22
+ a. latest. median. seconds/ a. baseline. median. seconds <
23
+ b. latest. median. seconds/ b. baseline. median. seconds
24
+ }
25
+ }
20
26
var body : some View {
21
27
VStack ( alignment: . leading) {
22
- ForEach ( comparisons ) { comparison in
23
- let new = comparison. latest . median . seconds
24
- let old = comparison. baseline . median. seconds
25
- Chart {
28
+ Chart {
29
+ ForEach ( sortedComparisons ) { comparison in
30
+ let new = comparison. latest . median. seconds
31
+ let old = comparison . baseline . median . seconds
26
32
chartBody (
27
33
name: comparison. name,
28
34
new: new,
29
35
old: old,
30
36
sampleCount: comparison. latest. samples)
31
37
}
32
- . chartXAxis {
33
- AxisMarks { value in
34
- AxisTick ( )
35
- AxisValueLabel {
36
- Text ( String ( format: " %.5fs " , value. as ( Double . self) !) )
37
- }
38
- }
39
- }
40
- . chartYAxis {
41
- AxisMarks { value in
42
- AxisGridLine ( )
43
- AxisValueLabel {
44
- HStack {
45
- Text ( value. as ( String . self) !)
46
- let delta = ( new - old) / old * 100
47
- Text ( String ( format: " %+.2f%% " , delta) )
48
- . foregroundColor ( delta <= 0 ? . green : . yellow)
49
- }
50
- }
51
- }
52
- }
53
- . frame ( idealHeight: 60 )
54
- }
38
+ // Baseline
39
+ RuleMark ( y: . value( " Time " , 1.0 ) )
40
+ . foregroundStyle ( . red)
41
+ . lineStyle ( . init( lineWidth: 1 , dash: [ 2 ] ) )
42
+
43
+ } . frame ( idealHeight: 400 )
55
44
}
56
45
}
57
46
@@ -62,27 +51,15 @@ struct BenchmarkChart: View {
62
51
old: TimeInterval ,
63
52
sampleCount: Int
64
53
) -> some ChartContent {
65
- // Baseline bar
66
- BarMark (
67
- x: . value( " Time " , old) ,
68
- y: . value( " Name " , " \( name) ( \( sampleCount) samples) " ) )
69
- . position ( by: . value( " Kind " , " Baseline " ) )
70
- . foregroundStyle ( . gray)
71
-
72
- // Latest result bar
54
+ // Normalized runtime
73
55
BarMark (
74
- x: . value( " Time " , new ) ,
75
- y: . value( " Name " , " \( name ) ( \( sampleCount ) samples) " ) )
76
- . position ( by : . value ( " Kind " , " Latest " ) )
56
+ x: . value( " Name " , name ) ,
57
+ y: . value( " Normalized runtime " , new / old ) )
58
+
77
59
. foregroundStyle ( LinearGradient (
78
60
colors: [ . accentColor, new - old <= 0 ? . green : . yellow] ,
79
- startPoint: . leading,
80
- endPoint: . trailing) )
81
-
82
- // Comparison
83
- RuleMark ( x: . value( " Time " , new) )
84
- . foregroundStyle ( . gray)
85
- . lineStyle ( . init( lineWidth: 0.5 , dash: [ 2 ] ) )
61
+ startPoint: . bottom,
62
+ endPoint: . top) )
86
63
}
87
64
}
88
65
0 commit comments