in Sources/CollectionsBenchmark/BenchmarkCLI/_Document.swift [104:177]
mutating func run(benchmark: Benchmark, options: Benchmark.Options) throws {
let tasks = try options.resolveTasks(from: benchmark)
let sizes = try options.resolveSizes()
print("""
Running \(tasks.count) tasks \
on \(sizes.count) sizes \
from \(sizes.first!) \
to \(sizes.last!):
""")
for task in tasks.prefix(20) {
print(" \(task.id)")
}
if tasks.count > 20 {
print(" (\(tasks.count - 20) more)")
}
print("Output file: \(url.absoluteURL.path)")
switch mode {
case .append:
print("Appending to existing data (if any) for these tasks/sizes.")
case .replace:
print("Discarding existing data (if any) for these tasks/sizes.")
results.clear(sizes: sizes, from: options.tasks)
case .replaceAll:
print("Discarding all existing data.")
results.clear()
}
// Register links to tasks if needed.
if let sourceURL = options.sourceURL.flatMap({ URL(string: $0) }) {
for id in options.tasks {
let task = benchmark.task(named: id.title)!
_results.add(TaskResults(id: id, link: task._sourceLink(base: sourceURL)))
}
}
print()
#if DEBUG
complain("WARNING: Running benchmarks in debug configuration.")
print()
#endif
print("Collecting data:")
let start = Tick.now
var needDot = false
try benchmark.run(options: options) { event in
switch event {
case .startCycle:
print(" ", terminator: "")
case let .stopCycle(tasks: _, sizes: _, time: time):
needDot = false
print(" -- \(time)")
try save()
case let .startSize(tasks: _, size: size):
if size.rawValue & (size.rawValue - 1) == 0 { // Power of two
if needDot { print(".", terminator: "")}
print("\(size)", terminator: "")
needDot = true
} else {
print(".", terminator: "")
needDot = false
}
case .stopSize:
break // Do nothing
case .startTask:
break // Do nothing
case let .stopTask(task: task, size: size, time: time):
results.add(id: task, size: size, time: time)
try saveIfNeeded()
}
}
// FIXME: Report memory usage stats, user/sys/wallclock time
print("Finished in \(Tick.now.elapsedTime(since: start))")
}