From 6ea1365a9ab3130b81bc3d9ebbb161e065d6aade Mon Sep 17 00:00:00 2001 From: Joakim Hassila Date: Tue, 21 Mar 2023 12:14:41 +0100 Subject: [PATCH] chore: Move to booleans instead of ints, fixes #114 (#118) --- Plugins/BenchmarkTool/BenchmarkTool+Operations.swift | 2 +- .../BenchmarkTool/BenchmarkTool+PrettyPrinting.swift | 12 ++++++------ Plugins/BenchmarkTool/BenchmarkTool.swift | 12 ++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Plugins/BenchmarkTool/BenchmarkTool+Operations.swift b/Plugins/BenchmarkTool/BenchmarkTool+Operations.swift index bd2fb297..5d1eb15b 100644 --- a/Plugins/BenchmarkTool/BenchmarkTool+Operations.swift +++ b/Plugins/BenchmarkTool/BenchmarkTool+Operations.swift @@ -130,7 +130,7 @@ extension BenchmarkTool { target: target) } - if quiet == 0 { + if quiet == false { print("") print("Updated baseline '\(baselineName)'") } diff --git a/Plugins/BenchmarkTool/BenchmarkTool+PrettyPrinting.swift b/Plugins/BenchmarkTool/BenchmarkTool+PrettyPrinting.swift index ad886c9d..20230646 100644 --- a/Plugins/BenchmarkTool/BenchmarkTool+PrettyPrinting.swift +++ b/Plugins/BenchmarkTool/BenchmarkTool+PrettyPrinting.swift @@ -100,7 +100,7 @@ extension BenchmarkTool { var adjustmentFunction: (Int) -> Int - if self.scale > 0, result.metrics.metric.useScalingFactor { + if self.scale, result.metrics.metric.useScalingFactor { description = useGroupingDescription ? "\(result.description) \(result.metrics.scaledUnitDescriptionPretty)" : "\(result.metrics.metric.description) \(result.metrics.scaledUnitDescriptionPretty)" adjustmentFunction = result.metrics.scale @@ -135,7 +135,7 @@ extension BenchmarkTool { func prettyPrint(_ baseline: BenchmarkBaseline, header: String, // = "Benchmark results", hostIdentifier _: String? = nil) { - guard quiet == 0 else { return } + guard quiet == false else { return } printMachine(baseline.machine, header) @@ -268,7 +268,7 @@ extension BenchmarkTool { var adjustmentFunction: (Int) -> Int let samples = result.statistics.measurementCount - base.statistics.measurementCount - if self.scale > 0, base.metric.useScalingFactor { + if self.scale, base.metric.useScalingFactor { adjustmentFunction = base.scale } else { adjustmentFunction = base.normalize @@ -286,7 +286,7 @@ extension BenchmarkTool { percentiles: basePercentiles, samples: base.statistics.measurementCount)) - if self.scale > 0, result.metric.useScalingFactor { + if self.scale, result.metric.useScalingFactor { adjustmentFunction = result.scale } else { adjustmentFunction = result.normalize @@ -369,7 +369,7 @@ extension BenchmarkTool { func prettyPrintDeviation(baselineName: String, comparingBaselineName: String, deviationResults: [BenchmarkResult.ThresholdDeviation]) { - guard quiet == 0 else { return } + guard quiet == false else { return } let metrics = deviationResults.map(\.metric).unique() // Get a unique set of all name/target pairs that have threshold violations, sorted lexically: @@ -433,7 +433,7 @@ extension BenchmarkTool { func prettyPrintAbsoluteDeviation(baselineName: String, deviationResults: [BenchmarkResult.ThresholdDeviation]) { - guard quiet == 0 else { return } + guard quiet == false else { return } let metrics = deviationResults.map(\.metric).unique() // Get a unique set of all name/target pairs that have threshold violations, sorted lexically: diff --git a/Plugins/BenchmarkTool/BenchmarkTool.swift b/Plugins/BenchmarkTool/BenchmarkTool.swift index 7c71ee06..a9dc5880 100644 --- a/Plugins/BenchmarkTool/BenchmarkTool.swift +++ b/Plugins/BenchmarkTool/BenchmarkTool.swift @@ -57,13 +57,13 @@ struct BenchmarkTool: AsyncParsableCommand { var baselineOperation: BaselineOperation? @Flag(name: .long, help: "True if we should suppress output") - var quiet: Int + var quiet: Bool = false @Flag(name: .long, help: "True if we should suppress progress in benchmark run") - var noProgress: Int + var noProgress: Bool = false @Flag(name: .long, help: "True if we should scale time units, syscall rate, etc to scalingFactor") - var scale: Int + var scale: Bool = false @Flag(name: .long, help: """ @@ -159,7 +159,7 @@ struct BenchmarkTool: AsyncParsableCommand { if let baseline = try readBaseline(baselineName) { benchmarkBaselines.append(baseline) } else { - if quiet == 0 { + if quiet == false { print("Warning: Failed to load specified baseline '\(baselineName)'.") } } @@ -210,7 +210,7 @@ struct BenchmarkTool: AsyncParsableCommand { fatalError("Query command should never be specified to the BenchmarkTool") } - if quiet == 0, format == .text { + if quiet == false, format == .text { "Running Benchmarks".printAsHeader() } @@ -265,7 +265,7 @@ struct BenchmarkTool: AsyncParsableCommand { var args: [String] = [path.lastComponent!.description, "--input-fd", toChild.readEnd.rawValue.description, "--output-fd", fromChild.writeEnd.rawValue.description, - "--quiet", (noProgress > 0).description] + "--quiet", noProgress.description] if checkAbsoluteThresholds { args.append("--check-absolute")