Skip to content

Commit

Permalink
Upgrade Measurement into a top-level type, with a compatibility alias
Browse files Browse the repository at this point in the history
  • Loading branch information
lorentey committed Apr 16, 2021
1 parent db30b38 commit faa1b2c
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 19 deletions.
22 changes: 22 additions & 0 deletions Sources/CollectionsBenchmark/Basics/Measurement.swift
@@ -0,0 +1,22 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Collections open source project
//
// Copyright (c) 2021 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
//===----------------------------------------------------------------------===//

/// A point in the document coordinate system, i.e., a pair of size and
/// time values.
public struct Measurement: Hashable, Codable {
public let size: Size
public let time: Time

public init(size: Size, time: Time) {
self.size = size
self.time = time
}
}
6 changes: 3 additions & 3 deletions Sources/CollectionsBenchmark/Basics/TaskResults.swift
Expand Up @@ -167,14 +167,14 @@ extension TaskResults {
for statistic: Sample.Statistic,
percentile: Double,
amortizedTime: Bool
) -> Curve<BenchmarkResults.Measurement> {
var curve = Curve<BenchmarkResults.Measurement>()
) -> Curve<Measurement> {
var curve = Curve<Measurement>()
for (size, sample) in _samples {
let sample = sample.discardingPercentile(above: percentile)
guard let time = sample[statistic] ?? sample[.mean] else { continue }

let t = amortizedTime ? time.amortized(over: size) : time
curve.points.append(BenchmarkResults.Measurement(size: size, time: t))
curve.points.append(Measurement(size: size, time: t))
}
return curve
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/CollectionsBenchmark/Charts/Band.swift
Expand Up @@ -90,7 +90,7 @@ extension Band {
}
}

extension Band where Element == Curve<BenchmarkResults.Measurement> {
extension Band where Element == Curve<Measurement> {
var sizeRange: ClosedRange<Size>? {
_union(bottom.sizeRange, _union(center.sizeRange, top.sizeRange))
}
Expand Down
2 changes: 0 additions & 2 deletions Sources/CollectionsBenchmark/Charts/Chart.swift
Expand Up @@ -13,8 +13,6 @@ import Foundation

/// The data for a benchmark chart in a nice preprocessed format.
public struct Chart {
public typealias Measurement = BenchmarkResults.Measurement

public let options: Options
public let sizeScale: ChartScale
public let timeScale: ChartScale
Expand Down
14 changes: 1 addition & 13 deletions Sources/CollectionsBenchmark/Charts/Curve.swift
Expand Up @@ -43,7 +43,7 @@ extension Curve {
}
}

extension Curve where Point == BenchmarkResults.Measurement {
extension Curve where Point == Measurement {
var sizeRange: ClosedRange<Size>? {
guard !points.isEmpty else { return nil }
let min = points.min(by: { $0.size < $1.size })
Expand All @@ -60,18 +60,6 @@ extension Curve where Point == BenchmarkResults.Measurement {
}

extension BenchmarkResults {
/// A point in the document coordinate system, i.e., a pair of size and
/// time values.
public struct Measurement: Hashable, Codable {
public let size: Size
public let time: Time

public init(size: Size, time: Time) {
self.size = size
self.time = time
}
}

public func curve(id: TaskID, statistic: Sample.Statistic) -> Curve<Measurement> {
let points: [Measurement] = self[id: id].compactMap { (size, sample) in
guard let time = sample[statistic] else { return nil }
Expand Down
16 changes: 16 additions & 0 deletions Sources/CollectionsBenchmark/Compatibility/Compatibility.swift
@@ -0,0 +1,16 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Collections open source project
//
// Copyright (c) 2021 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
//===----------------------------------------------------------------------===//

extension BenchmarkResults {
// Deprecated since 0.0.2
@available(*, deprecated, renamed: "Measurement")
public typealias Point = Measurement
}

0 comments on commit faa1b2c

Please sign in to comment.