[swcomp] Add --no-warmup option to benchmark commands

This commit is contained in:
Timofey Solomko
2022-01-24 21:31:54 +03:00
parent 3ac1a6b378
commit 8302790ae2
2 changed files with 70 additions and 16 deletions
@@ -17,6 +17,7 @@ protocol BenchmarkCommand: Command {
associatedtype OutputType
var iterationCount: Int? { get }
var noWarmup: Bool { get }
var inputs: [String] { get }
@@ -102,20 +103,25 @@ extension BenchmarkCommand {
#if !os(Linux)
fflush(__stdoutp)
#endif
// Zeroth (excluded) iteration.
self.iterationSetUp()
let startTime = CFAbsoluteTimeGetCurrent()
let warmupOutput = self.benchmark()
let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime
let speed = benchmarkInputSize! / timeElapsed
print("(\(formatter.string(from: speed)))", terminator: "")
#if !os(Linux)
fflush(__stdoutp)
#endif
self.iterationTearDown()
var warmupOutput: OutputType? = nil
if !self.noWarmup {
// Zeroth (excluded) iteration.
self.iterationSetUp()
let startTime = CFAbsoluteTimeGetCurrent()
warmupOutput = self.benchmark()
let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime
let speed = benchmarkInputSize! / timeElapsed
print("(\(formatter.string(from: speed)))", terminator: "")
#if !os(Linux)
fflush(__stdoutp)
#endif
self.iterationTearDown()
}
for _ in 1...(self.iterationCount ?? 10) {
print(", ", terminator: "")
for i in 1...(self.iterationCount ?? 10) {
if i > 1 || !noWarmup {
print(", ", terminator: "")
}
self.iterationSetUp()
let startTime = CFAbsoluteTimeGetCurrent()
self.benchmark()
@@ -143,9 +149,15 @@ extension BenchmarkCommand {
avgString += formatter.string(from: speedUncertainty, units: avgSpeedUnits)
print(avgString)
if let outputData = warmupOutput as? Data, calculateCompressionRatio, outputData.count > 0 {
let compressionRatio = Double(benchmarkInputSize!) / Double(outputData.count)
print(String(format: "Compression ratio: %.3f", compressionRatio))
if calculateCompressionRatio {
if warmupOutput == nil {
print("WARNING: Unable to calculate compression ratio without a warmup iteration.")
} else if let outputData = warmupOutput as? Data, outputData.count > 0 {
let compressionRatio = Double(benchmarkInputSize!) / Double(outputData.count)
print(String(format: "Compression ratio: %.3f", compressionRatio))
} else {
print("WARNING: Unable to calculate compression ratio.")
}
}
print()
self.benchmarkTearDown()
@@ -29,6 +29,9 @@ final class CompBz2: BenchmarkCommand {
@Key("-i", "--iteration-count", description: "Sets the amount of the benchmark iterations (default: 10)")
var iterationCount: Int?
@Flag("--no-warmup", description: "Disables warmup iteration")
var noWarmup: Bool
@CollectedParam(minCount: 1) var inputs: [String]
let benchmarkName = "BZip2 Compression"
@@ -52,6 +55,9 @@ final class CompDeflate: BenchmarkCommand {
@Key("-i", "--iteration-count", description: "Sets the amount of the benchmark iterations (default: 10)")
var iterationCount: Int?
@Flag("--no-warmup", description: "Disables warmup iteration")
var noWarmup: Bool
@CollectedParam(minCount: 1) var inputs: [String]
let benchmarkName = "Deflate Compression"
@@ -75,6 +81,9 @@ final class CompLZ4: BenchmarkCommand {
@Key("-i", "--iteration-count", description: "Sets the amount of the benchmark iterations (default: 10)")
var iterationCount: Int?
@Flag("--no-warmup", description: "Disables warmup iteration")
var noWarmup: Bool
@CollectedParam(minCount: 1) var inputs: [String]
let benchmarkName = "LZ4 Compression with independent blocks"
@@ -98,6 +107,9 @@ final class CompLZ4BD: BenchmarkCommand {
@Key("-i", "--iteration-count", description: "Sets the amount of the benchmark iterations (default: 10)")
var iterationCount: Int?
@Flag("--no-warmup", description: "Disables warmup iteration")
var noWarmup: Bool
@CollectedParam(minCount: 1) var inputs: [String]
let benchmarkName = "LZ4 Compression with dependent blocks"
@@ -125,6 +137,9 @@ final class Info7z: BenchmarkCommand {
@Key("-i", "--iteration-count", description: "Sets the amount of the benchmark iterations (default: 10)")
var iterationCount: Int?
@Flag("--no-warmup", description: "Disables warmup iteration")
var noWarmup: Bool
@CollectedParam(minCount: 1) var inputs: [String]
let benchmarkName = "7-Zip info function"
@@ -151,6 +166,9 @@ final class InfoTar: BenchmarkCommand {
@Key("-i", "--iteration-count", description: "Sets the amount of the benchmark iterations (default: 10)")
var iterationCount: Int?
@Flag("--no-warmup", description: "Disables warmup iteration")
var noWarmup: Bool
@CollectedParam(minCount: 1) var inputs: [String]
let benchmarkName = "TAR info function"
@@ -177,6 +195,9 @@ final class InfoZip: BenchmarkCommand {
@Key("-i", "--iteration-count", description: "Sets the amount of the benchmark iterations (default: 10)")
var iterationCount: Int?
@Flag("--no-warmup", description: "Disables warmup iteration")
var noWarmup: Bool
@CollectedParam(minCount: 1) var inputs: [String]
let benchmarkName = "ZIP info function"
@@ -203,6 +224,9 @@ final class UnBz2: BenchmarkCommand {
@Key("-i", "--iteration-count", description: "Sets the amount of the benchmark iterations (default: 10)")
var iterationCount: Int?
@Flag("--no-warmup", description: "Disables warmup iteration")
var noWarmup: Bool
@CollectedParam(minCount: 1) var inputs: [String]
let benchmarkName = "BZip2 Unarchive"
@@ -229,6 +253,9 @@ final class UnGzip: BenchmarkCommand {
@Key("-i", "--iteration-count", description: "Sets the amount of the benchmark iterations (default: 10)")
var iterationCount: Int?
@Flag("--no-warmup", description: "Disables warmup iteration")
var noWarmup: Bool
@CollectedParam(minCount: 1) var inputs: [String]
let benchmarkName = "GZip Unarchive"
@@ -255,6 +282,9 @@ final class UnLZ4: BenchmarkCommand {
@Key("-i", "--iteration-count", description: "Sets the amount of the benchmark iterations (default: 10)")
var iterationCount: Int?
@Flag("--no-warmup", description: "Disables warmup iteration")
var noWarmup: Bool
@CollectedParam(minCount: 1) var inputs: [String]
let benchmarkName = "LZ4 Unarchive"
@@ -281,6 +311,9 @@ final class UnXz: BenchmarkCommand {
@Key("-i", "--iteration-count", description: "Sets the amount of the benchmark iterations (default: 10)")
var iterationCount: Int?
@Flag("--no-warmup", description: "Disables warmup iteration")
var noWarmup: Bool
@CollectedParam(minCount: 1) var inputs: [String]
let benchmarkName = "XZ Unarchive"
@@ -307,6 +340,9 @@ final class CreateTar: BenchmarkCommand {
@Key("-i", "--iteration-count", description: "Sets the amount of the benchmark iterations (default: 10)")
var iterationCount: Int?
@Flag("--no-warmup", description: "Disables warmup iteration")
var noWarmup: Bool
@CollectedParam(minCount: 1) var inputs: [String]
let benchmarkName = "TAR Create"
@@ -338,6 +374,9 @@ final class ReaderTar: BenchmarkCommand {
@Key("-i", "--iteration-count", description: "Sets the amount of the benchmark iterations (default: 10)")
var iterationCount: Int?
@Flag("--no-warmup", description: "Disables warmup iteration")
var noWarmup: Bool
@CollectedParam(minCount: 1) var inputs: [String]
let benchmarkName = "TAR Reader"
@@ -413,6 +452,9 @@ final class WriterTar: BenchmarkCommand {
@Key("-i", "--iteration-count", description: "Sets the amount of the benchmark iterations (default: 10)")
var iterationCount: Int?
@Flag("--no-warmup", description: "Disables warmup iteration")
var noWarmup: Bool
@CollectedParam(minCount: 1) var inputs: [String]
let benchmarkName = "TAR Writer"