|
1 |
| -//===----------------------------------------------------------------------===// |
| 1 | +////===----------------------------------------------------------------------===// |
| 2 | +//// |
| 3 | +//// This source file is part of the Swift.org open source project |
| 4 | +//// |
| 5 | +//// Copyright (c) 2021-2022 Apple Inc. and the Swift project authors |
| 6 | +//// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +//// |
| 8 | +//// See https://swift.org/LICENSE.txt for license information |
| 9 | +//// |
| 10 | +////===----------------------------------------------------------------------===// |
2 | 11 | //
|
3 |
| -// This source file is part of the Swift.org open source project |
| 12 | +//#if os(macOS) && canImport(Charts) |
4 | 13 | //
|
5 |
| -// Copyright (c) 2021-2022 Apple Inc. and the Swift project authors |
6 |
| -// Licensed under Apache License v2.0 with Runtime Library Exception |
| 14 | +//import Charts |
| 15 | +//import SwiftUI |
7 | 16 | //
|
8 |
| -// See https://swift.org/LICENSE.txt for license information |
| 17 | +//struct BenchmarkChart: View { |
| 18 | +// var comparisons: [BenchmarkResult.Comparison] |
9 | 19 | //
|
10 |
| -//===----------------------------------------------------------------------===// |
11 |
| - |
12 |
| -#if os(macOS) && canImport(Charts) |
13 |
| - |
14 |
| -import Charts |
15 |
| -import SwiftUI |
16 |
| - |
17 |
| -struct BenchmarkChart: View { |
18 |
| - var comparisons: [BenchmarkResult.Comparison] |
19 |
| - |
20 |
| - // Sort by normalized difference |
21 |
| - var sortedComparisons: [BenchmarkResult.Comparison] { |
22 |
| - comparisons.sorted { a, b in |
23 |
| - a.normalizedDiff < b.normalizedDiff |
24 |
| - } |
25 |
| - } |
26 |
| - var body: some View { |
27 |
| - VStack(alignment: .leading) { |
28 |
| - Chart { |
29 |
| - ForEach(sortedComparisons) { comparison in |
30 |
| - // Normalized runtime |
31 |
| - BarMark( |
32 |
| - x: .value("Name", comparison.name), |
33 |
| - y: .value("Normalized runtime", comparison.normalizedDiff)) |
34 |
| - .foregroundStyle(LinearGradient( |
35 |
| - colors: [.accentColor, comparison.diff?.seconds ?? 0 <= 0 ? .green : .yellow], |
36 |
| - startPoint: .bottom, |
37 |
| - endPoint: .top)) |
38 |
| - } |
39 |
| - // Baseline |
40 |
| - RuleMark(y: .value("Time", 1.0)) |
41 |
| - .foregroundStyle(.red) |
42 |
| - .lineStyle(.init(lineWidth: 1, dash: [2])) |
43 |
| - .annotation(position: .top, alignment: .leading) { |
44 |
| - Text("Baseline").foregroundStyle(.red) |
45 |
| - } |
46 |
| - |
47 |
| - } |
48 |
| - .frame(idealWidth: 800, idealHeight: 800) |
49 |
| - .chartYScale(domain: 0...2.0) |
50 |
| - .chartYAxis { |
51 |
| - AxisMarks(values: .stride(by: 0.1)) |
52 |
| - } |
53 |
| - .chartXAxis { |
54 |
| - AxisMarks { value in |
55 |
| - AxisGridLine() |
56 |
| - AxisTick() |
57 |
| - AxisValueLabel(value.as(String.self)!, orientation: .vertical) |
58 |
| - } |
59 |
| - } |
60 |
| - } |
61 |
| - } |
62 |
| -} |
63 |
| - |
64 |
| -struct BenchmarkResultApp: App { |
65 |
| - static var comparisons: [BenchmarkResult.Comparison]? |
66 |
| - |
67 |
| - var body: some Scene { |
68 |
| - WindowGroup { |
69 |
| - if let comparisons = Self.comparisons { |
70 |
| - ScrollView { |
71 |
| - BenchmarkChart(comparisons: comparisons) |
72 |
| - } |
73 |
| - } else { |
74 |
| - Text("No data") |
75 |
| - } |
76 |
| - } |
77 |
| - } |
78 |
| -} |
79 |
| - |
80 |
| -#endif |
| 20 | +// // Sort by normalized difference |
| 21 | +// var sortedComparisons: [BenchmarkResult.Comparison] { |
| 22 | +// comparisons.sorted { a, b in |
| 23 | +// a.normalizedDiff < b.normalizedDiff |
| 24 | +// } |
| 25 | +// } |
| 26 | +// var body: some View { |
| 27 | +// VStack(alignment: .leading) { |
| 28 | +// Chart { |
| 29 | +// ForEach(sortedComparisons) { comparison in |
| 30 | +// // Normalized runtime |
| 31 | +// BarMark( |
| 32 | +// x: .value("Name", comparison.name), |
| 33 | +// y: .value("Normalized runtime", comparison.normalizedDiff)) |
| 34 | +// .foregroundStyle(LinearGradient( |
| 35 | +// colors: [.accentColor, comparison.diff?.seconds ?? 0 <= 0 ? .green : .yellow], |
| 36 | +// startPoint: .bottom, |
| 37 | +// endPoint: .top)) |
| 38 | +// } |
| 39 | +// // Baseline |
| 40 | +// RuleMark(y: .value("Time", 1.0)) |
| 41 | +// .foregroundStyle(.red) |
| 42 | +// .lineStyle(.init(lineWidth: 1, dash: [2])) |
| 43 | +// .annotation(position: .top, alignment: .leading) { |
| 44 | +// Text("Baseline").foregroundStyle(.red) |
| 45 | +// } |
| 46 | +// |
| 47 | +// } |
| 48 | +// .frame(idealWidth: 800, idealHeight: 800) |
| 49 | +// .chartYScale(domain: 0...2.0) |
| 50 | +// .chartYAxis { |
| 51 | +// AxisMarks(values: .stride(by: 0.1)) |
| 52 | +// } |
| 53 | +// .chartXAxis { |
| 54 | +// AxisMarks { value in |
| 55 | +// AxisGridLine() |
| 56 | +// AxisTick() |
| 57 | +// AxisValueLabel(value.as(String.self)!, orientation: .vertical) |
| 58 | +// } |
| 59 | +// } |
| 60 | +// } |
| 61 | +// } |
| 62 | +//} |
| 63 | +// |
| 64 | +//struct BenchmarkResultApp: App { |
| 65 | +// static var comparisons: [BenchmarkResult.Comparison]? |
| 66 | +// |
| 67 | +// var body: some Scene { |
| 68 | +// WindowGroup { |
| 69 | +// if let comparisons = Self.comparisons { |
| 70 | +// ScrollView { |
| 71 | +// BenchmarkChart(comparisons: comparisons) |
| 72 | +// } |
| 73 | +// } else { |
| 74 | +// Text("No data") |
| 75 | +// } |
| 76 | +// } |
| 77 | +// } |
| 78 | +//} |
| 79 | +// |
| 80 | +//#endif |
0 commit comments