mirror of
https://github.com/tsolomko/SWCompression.git
synced 2026-06-23 14:56:41 +00:00
[swcomp] Rewrite benchmark commands using new BenchmarkCommand protocol
This commit is contained in:
@@ -7,50 +7,14 @@ import Foundation
|
||||
import SWCompression
|
||||
import SwiftCLI
|
||||
|
||||
#if os(Linux)
|
||||
import CoreFoundation
|
||||
#endif
|
||||
|
||||
class CompBz2: Command {
|
||||
class CompBz2: BenchmarkCommand {
|
||||
|
||||
let name = "comp-bz2"
|
||||
let shortDescription = "Performs benchmarking of BZip2 compression using specified files"
|
||||
|
||||
let files = CollectedParameter()
|
||||
|
||||
func execute() throws {
|
||||
print("BZip2 Compression Benchmark")
|
||||
print("===========================")
|
||||
|
||||
for file in self.files.value {
|
||||
print("File: \(file)\n")
|
||||
|
||||
let inputURL = URL(fileURLWithPath: file)
|
||||
let fileData = try Data(contentsOf: inputURL, options: .mappedIfSafe)
|
||||
|
||||
var totalTime: Double = 0
|
||||
|
||||
var maxTime = Double(Int.min)
|
||||
var minTime = Double(Int.max)
|
||||
|
||||
_ = BZip2.compress(data: fileData)
|
||||
for i in 1...10 {
|
||||
print("Iteration \(i): ", terminator: "")
|
||||
let startTime = CFAbsoluteTimeGetCurrent()
|
||||
_ = BZip2.compress(data: fileData)
|
||||
let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime
|
||||
print(String(format: "%.3f", timeElapsed))
|
||||
totalTime += timeElapsed
|
||||
if timeElapsed > maxTime {
|
||||
maxTime = timeElapsed
|
||||
}
|
||||
if timeElapsed < minTime {
|
||||
minTime = timeElapsed
|
||||
}
|
||||
}
|
||||
print(String(format: "\nAverage time: %.3f \u{B1} %.3f", totalTime / 10, (maxTime - minTime) / 2))
|
||||
print("-----------------------------------")
|
||||
}
|
||||
}
|
||||
let benchmarkName = "BZip2 Compression"
|
||||
let benchmarkFunction: (Data) throws -> Any = BZip2.compress
|
||||
|
||||
}
|
||||
|
||||
@@ -7,50 +7,14 @@ import Foundation
|
||||
import SWCompression
|
||||
import SwiftCLI
|
||||
|
||||
#if os(Linux)
|
||||
import CoreFoundation
|
||||
#endif
|
||||
|
||||
class CompDeflate: Command {
|
||||
class CompDeflate: BenchmarkCommand {
|
||||
|
||||
let name = "comp-deflate"
|
||||
let shortDescription = "Performs benchmarking of Deflate compression using specified files"
|
||||
|
||||
let files = CollectedParameter()
|
||||
|
||||
func execute() throws {
|
||||
print("Deflate Compression Benchmark")
|
||||
print("=============================")
|
||||
|
||||
for file in self.files.value {
|
||||
print("File: \(file)\n")
|
||||
|
||||
let inputURL = URL(fileURLWithPath: file)
|
||||
let fileData = try Data(contentsOf: inputURL, options: .mappedIfSafe)
|
||||
|
||||
var totalTime: Double = 0
|
||||
|
||||
var maxTime = Double(Int.min)
|
||||
var minTime = Double(Int.max)
|
||||
|
||||
_ = Deflate.compress(data: fileData)
|
||||
for i in 1...10 {
|
||||
print("Iteration \(i): ", terminator: "")
|
||||
let startTime = CFAbsoluteTimeGetCurrent()
|
||||
_ = Deflate.compress(data: fileData)
|
||||
let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime
|
||||
print(String(format: "%.3f", timeElapsed))
|
||||
totalTime += timeElapsed
|
||||
if timeElapsed > maxTime {
|
||||
maxTime = timeElapsed
|
||||
}
|
||||
if timeElapsed < minTime {
|
||||
minTime = timeElapsed
|
||||
}
|
||||
}
|
||||
print(String(format: "\nAverage time: %.3f \u{B1} %.3f", totalTime / 10, (maxTime - minTime) / 2))
|
||||
print("----------------------------------")
|
||||
}
|
||||
}
|
||||
let benchmarkName = "Deflate Compression"
|
||||
let benchmarkFunction: (Data) throws -> Any = Deflate.compress
|
||||
|
||||
}
|
||||
|
||||
@@ -7,50 +7,14 @@ import Foundation
|
||||
import SWCompression
|
||||
import SwiftCLI
|
||||
|
||||
#if os(Linux)
|
||||
import CoreFoundation
|
||||
#endif
|
||||
|
||||
class Info7z: Command {
|
||||
class Info7z: BenchmarkCommand {
|
||||
|
||||
let name = "info-7z"
|
||||
let shortDescription = "Performs benchmarking of 7-Zip info function using specified files"
|
||||
|
||||
let files = CollectedParameter()
|
||||
|
||||
func execute() throws {
|
||||
print("7-Zip info function Benchmark")
|
||||
print("=============================")
|
||||
|
||||
for file in self.files.value {
|
||||
print("File: \(file)\n")
|
||||
|
||||
let inputURL = URL(fileURLWithPath: file)
|
||||
let fileData = try Data(contentsOf: inputURL, options: .mappedIfSafe)
|
||||
|
||||
var totalTime: Double = 0
|
||||
|
||||
var maxTime = Double(Int.min)
|
||||
var minTime = Double(Int.max)
|
||||
|
||||
_ = try SevenZipContainer.info(container: fileData)
|
||||
for i in 1...10 {
|
||||
print("Iteration \(i): ", terminator: "")
|
||||
let startTime = CFAbsoluteTimeGetCurrent()
|
||||
_ = try SevenZipContainer.info(container: fileData)
|
||||
let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime
|
||||
print(String(format: "%.3f", timeElapsed))
|
||||
totalTime += timeElapsed
|
||||
if timeElapsed > maxTime {
|
||||
maxTime = timeElapsed
|
||||
}
|
||||
if timeElapsed < minTime {
|
||||
minTime = timeElapsed
|
||||
}
|
||||
}
|
||||
print(String(format: "\nAverage time: %.3f \u{B1} %.3f", totalTime / 10, (maxTime - minTime) / 2))
|
||||
print("---------------------------------------")
|
||||
}
|
||||
}
|
||||
let benchmarkName = "7-Zip info function"
|
||||
let benchmarkFunction: (Data) throws -> Any = SevenZipContainer.info
|
||||
|
||||
}
|
||||
|
||||
@@ -7,50 +7,14 @@ import Foundation
|
||||
import SWCompression
|
||||
import SwiftCLI
|
||||
|
||||
#if os(Linux)
|
||||
import CoreFoundation
|
||||
#endif
|
||||
|
||||
class InfoTar: Command {
|
||||
class InfoTar: BenchmarkCommand {
|
||||
|
||||
let name = "info-tar"
|
||||
let shortDescription = "Performs benchmarking of TAR info function using specified files"
|
||||
|
||||
let files = CollectedParameter()
|
||||
|
||||
func execute() throws {
|
||||
print("TAR info function Benchmark")
|
||||
print("===========================")
|
||||
|
||||
for file in self.files.value {
|
||||
print("File: \(file)\n")
|
||||
|
||||
let inputURL = URL(fileURLWithPath: file)
|
||||
let fileData = try Data(contentsOf: inputURL, options: .mappedIfSafe)
|
||||
|
||||
var totalTime: Double = 0
|
||||
|
||||
var maxTime = Double(Int.min)
|
||||
var minTime = Double(Int.max)
|
||||
|
||||
_ = try TarContainer.info(container: fileData)
|
||||
for i in 1...10 {
|
||||
print("Iteration \(i): ", terminator: "")
|
||||
let startTime = CFAbsoluteTimeGetCurrent()
|
||||
_ = try TarContainer.info(container: fileData)
|
||||
let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime
|
||||
print(String(format: "%.3f", timeElapsed))
|
||||
totalTime += timeElapsed
|
||||
if timeElapsed > maxTime {
|
||||
maxTime = timeElapsed
|
||||
}
|
||||
if timeElapsed < minTime {
|
||||
minTime = timeElapsed
|
||||
}
|
||||
}
|
||||
print(String(format: "\nAverage time: %.3f \u{B1} %.3f", totalTime / 10, (maxTime - minTime) / 2))
|
||||
print("-------------------------------------")
|
||||
}
|
||||
}
|
||||
let benchmarkName = "TAR info function"
|
||||
let benchmarkFunction: (Data) throws -> Any = TarContainer.info
|
||||
|
||||
}
|
||||
|
||||
@@ -7,50 +7,14 @@ import Foundation
|
||||
import SWCompression
|
||||
import SwiftCLI
|
||||
|
||||
#if os(Linux)
|
||||
import CoreFoundation
|
||||
#endif
|
||||
|
||||
class InfoZip: Command {
|
||||
class InfoZip: BenchmarkCommand {
|
||||
|
||||
let name = "info-zip"
|
||||
let shortDescription = "Performs benchmarking of ZIP info function using specified files"
|
||||
|
||||
let files = CollectedParameter()
|
||||
|
||||
func execute() throws {
|
||||
print("ZIP info function Benchmark")
|
||||
print("===========================")
|
||||
|
||||
for file in self.files.value {
|
||||
print("File: \(file)\n")
|
||||
|
||||
let inputURL = URL(fileURLWithPath: file)
|
||||
let fileData = try Data(contentsOf: inputURL, options: .mappedIfSafe)
|
||||
|
||||
var totalTime: Double = 0
|
||||
|
||||
var maxTime = Double(Int.min)
|
||||
var minTime = Double(Int.max)
|
||||
|
||||
_ = try ZipContainer.info(container: fileData)
|
||||
for i in 1...10 {
|
||||
print("Iteration \(i): ", terminator: "")
|
||||
let startTime = CFAbsoluteTimeGetCurrent()
|
||||
_ = try ZipContainer.info(container: fileData)
|
||||
let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime
|
||||
print(String(format: "%.3f", timeElapsed))
|
||||
totalTime += timeElapsed
|
||||
if timeElapsed > maxTime {
|
||||
maxTime = timeElapsed
|
||||
}
|
||||
if timeElapsed < minTime {
|
||||
minTime = timeElapsed
|
||||
}
|
||||
}
|
||||
print(String(format: "\nAverage time: %.3f \u{B1} %.3f", totalTime / 10, (maxTime - minTime) / 2))
|
||||
print("-------------------------------------")
|
||||
}
|
||||
}
|
||||
let benchmarkName = "ZIP info function"
|
||||
let benchmarkFunction: (Data) throws -> Any = ZipContainer.info
|
||||
|
||||
}
|
||||
|
||||
@@ -7,50 +7,14 @@ import Foundation
|
||||
import SWCompression
|
||||
import SwiftCLI
|
||||
|
||||
#if os(Linux)
|
||||
import CoreFoundation
|
||||
#endif
|
||||
|
||||
class UnBz2: Command {
|
||||
class UnBz2: BenchmarkCommand {
|
||||
|
||||
let name = "un-bz2"
|
||||
let shortDescription = "Performs benchmarking of BZip2 unarchiving using specified files"
|
||||
|
||||
let files = CollectedParameter()
|
||||
|
||||
func execute() throws {
|
||||
print("BZip2 Unarchive Benchmark")
|
||||
print("=========================")
|
||||
|
||||
for file in self.files.value {
|
||||
print("File: \(file)\n")
|
||||
|
||||
let inputURL = URL(fileURLWithPath: file)
|
||||
let fileData = try Data(contentsOf: inputURL, options: .mappedIfSafe)
|
||||
|
||||
var totalTime: Double = 0
|
||||
|
||||
var maxTime = Double(Int.min)
|
||||
var minTime = Double(Int.max)
|
||||
|
||||
_ = try BZip2.decompress(data: fileData)
|
||||
for i in 1...10 {
|
||||
print("Iteration \(i): ", terminator: "")
|
||||
let startTime = CFAbsoluteTimeGetCurrent()
|
||||
_ = try BZip2.decompress(data: fileData)
|
||||
let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime
|
||||
print(String(format: "%.3f", timeElapsed))
|
||||
totalTime += timeElapsed
|
||||
if timeElapsed > maxTime {
|
||||
maxTime = timeElapsed
|
||||
}
|
||||
if timeElapsed < minTime {
|
||||
minTime = timeElapsed
|
||||
}
|
||||
}
|
||||
print(String(format: "\nAverage time: %.3f \u{B1} %.3f", totalTime / 10, (maxTime - minTime) / 2))
|
||||
print("-----------------------------------")
|
||||
}
|
||||
}
|
||||
let benchmarkName = "BZip2 Unarchive"
|
||||
let benchmarkFunction: (Data) throws -> Any = BZip2.decompress
|
||||
|
||||
}
|
||||
|
||||
@@ -7,50 +7,14 @@ import Foundation
|
||||
import SWCompression
|
||||
import SwiftCLI
|
||||
|
||||
#if os(Linux)
|
||||
import CoreFoundation
|
||||
#endif
|
||||
|
||||
class UnGzip: Command {
|
||||
class UnGzip: BenchmarkCommand {
|
||||
|
||||
let name = "un-gzip"
|
||||
let shortDescription = "Performs benchmarking of GZip unarchiving using specified files"
|
||||
|
||||
let files = CollectedParameter()
|
||||
|
||||
func execute() throws {
|
||||
print("GZip Unarchive Benchmark")
|
||||
print("========================")
|
||||
|
||||
for file in self.files.value {
|
||||
print("File: \(file)\n")
|
||||
|
||||
let inputURL = URL(fileURLWithPath: file)
|
||||
let fileData = try Data(contentsOf: inputURL, options: .mappedIfSafe)
|
||||
|
||||
var totalTime: Double = 0
|
||||
|
||||
var maxTime = Double(Int.min)
|
||||
var minTime = Double(Int.max)
|
||||
|
||||
_ = try GzipArchive.unarchive(archive: fileData)
|
||||
for i in 1...10 {
|
||||
print("Iteration \(i): ", terminator: "")
|
||||
let startTime = CFAbsoluteTimeGetCurrent()
|
||||
_ = try GzipArchive.unarchive(archive: fileData)
|
||||
let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime
|
||||
print(String(format: "%.3f", timeElapsed))
|
||||
totalTime += timeElapsed
|
||||
if timeElapsed > maxTime {
|
||||
maxTime = timeElapsed
|
||||
}
|
||||
if timeElapsed < minTime {
|
||||
minTime = timeElapsed
|
||||
}
|
||||
}
|
||||
print(String(format: "\nAverage time: %.3f \u{B1} %.3f", totalTime / 10, (maxTime - minTime) / 2))
|
||||
print("----------------------------------")
|
||||
}
|
||||
}
|
||||
let benchmarkName = "GZip Unarchive"
|
||||
let benchmarkFunction: (Data) throws -> Any = GzipArchive.unarchive
|
||||
|
||||
}
|
||||
|
||||
@@ -7,50 +7,14 @@ import Foundation
|
||||
import SWCompression
|
||||
import SwiftCLI
|
||||
|
||||
#if os(Linux)
|
||||
import CoreFoundation
|
||||
#endif
|
||||
|
||||
class UnXz: Command {
|
||||
class UnXz: BenchmarkCommand {
|
||||
|
||||
let name = "un-xz"
|
||||
let shortDescription = "Performs benchmarking of XZ unarchiving using specified files"
|
||||
|
||||
let files = CollectedParameter()
|
||||
|
||||
func execute() throws {
|
||||
print("XZ Unarchive Benchmark")
|
||||
print("======================")
|
||||
|
||||
for file in self.files.value {
|
||||
print("File: \(file)\n")
|
||||
|
||||
let inputURL = URL(fileURLWithPath: file)
|
||||
let fileData = try Data(contentsOf: inputURL, options: .mappedIfSafe)
|
||||
|
||||
var totalTime: Double = 0
|
||||
|
||||
var maxTime = Double(Int.min)
|
||||
var minTime = Double(Int.max)
|
||||
|
||||
_ = try XZArchive.unarchive(archive: fileData)
|
||||
for i in 1...10 {
|
||||
print("Iteration \(i): ", terminator: "")
|
||||
let startTime = CFAbsoluteTimeGetCurrent()
|
||||
_ = try XZArchive.unarchive(archive: fileData)
|
||||
let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime
|
||||
print(String(format: "%.3f", timeElapsed))
|
||||
totalTime += timeElapsed
|
||||
if timeElapsed > maxTime {
|
||||
maxTime = timeElapsed
|
||||
}
|
||||
if timeElapsed < minTime {
|
||||
minTime = timeElapsed
|
||||
}
|
||||
}
|
||||
print(String(format: "\nAverage time: %.3f \u{B1} %.3f", totalTime / 10, (maxTime - minTime) / 2))
|
||||
print("--------------------------------")
|
||||
}
|
||||
}
|
||||
let benchmarkName = "XZ Unarchive"
|
||||
let benchmarkFunction: (Data) throws -> Any = XZArchive.unarchive
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user