Skip to content

[benchmark] Janitor Duty: Sisyphus Legacy #22296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Feb 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 33 additions & 66 deletions benchmark/single-source/SequenceAlgos.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===--- ArrayAppend.swift ------------------------------------------------===//
//===--- SequenceAlgos.swift ----------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
Expand All @@ -18,13 +18,34 @@ import TestsUtils
// To avoid too many little micro benchmarks, it measures them all together
// for each sequence type.

let t: [BenchmarkCategory] = [.validation, .api]

public let SequenceAlgos = [
BenchmarkInfo(name: "SequenceAlgosList", runFunction: run_SequenceAlgosList, tags: [.validation, .api], setUpFunction: { buildWorkload() }, tearDownFunction: nil),
BenchmarkInfo(name: "SequenceAlgosArray", runFunction: run_SequenceAlgosArray, tags: [.validation, .api], setUpFunction: { buildWorkload() }, tearDownFunction: nil),
BenchmarkInfo(name: "SequenceAlgosContiguousArray", runFunction: run_SequenceAlgosContiguousArray, tags: [.validation, .api], setUpFunction: { buildWorkload() }, tearDownFunction: nil),
BenchmarkInfo(name: "SequenceAlgosRange", runFunction: run_SequenceAlgosRange, tags: [.validation, .api], setUpFunction: { buildWorkload() }, tearDownFunction: nil),
BenchmarkInfo(name: "SequenceAlgosUnfoldSequence", runFunction: run_SequenceAlgosUnfoldSequence, tags: [.validation, .api], setUpFunction: { buildWorkload() }, tearDownFunction: nil),
BenchmarkInfo(name: "SequenceAlgosAnySequence", runFunction: run_SequenceAlgosAnySequence, tags: [.validation, .api], setUpFunction: { buildWorkload() }, tearDownFunction: nil),
BenchmarkInfo(name: "SequenceAlgosList", runFunction: { for _ in 0..<$0 {
benchmarkSequenceAlgos(s: l, n: n)
benchmarkEquatableSequenceAlgos(s: l, n: n)
}}, tags: t, setUpFunction: { blackHole(l) }, legacyFactor: 10),
BenchmarkInfo(name: "SequenceAlgosArray", runFunction: { for _ in 0..<$0 {
benchmarkSequenceAlgos(s: a, n: a.count)
benchmarkEquatableSequenceAlgos(s: a, n: a.count)
}}, tags: t, setUpFunction: { blackHole(a) }, legacyFactor: 10),
BenchmarkInfo(name: "SequenceAlgosContiguousArray",
runFunction: { for _ in 0..<$0 {
benchmarkSequenceAlgos(s: c, n: c.count)
benchmarkEquatableSequenceAlgos(s: c, n: c.count)
}}, tags: t, setUpFunction: { blackHole(c) }, legacyFactor: 10),
BenchmarkInfo(name: "SequenceAlgosRange", runFunction: { for _ in 0..<$0 {
benchmarkSequenceAlgos(s: r, n: r.count)
benchmarkEquatableSequenceAlgos(s: r, n: r.count)
}}, tags: t, legacyFactor: 10),
BenchmarkInfo(name: "SequenceAlgosUnfoldSequence",
runFunction: { for _ in 0..<$0 {
benchmarkSequenceAlgos(s: s, n: n)
}}, tags: t, setUpFunction: { blackHole(s) }, legacyFactor: 10),
BenchmarkInfo(name: "SequenceAlgosAnySequence",
runFunction: { for _ in 0..<$0 {
benchmarkSequenceAlgos(s: y, n: n/10)
}}, tags: t, setUpFunction: { blackHole(y) }, legacyFactor: 100),
]

extension List: Sequence {
Expand Down Expand Up @@ -55,79 +76,25 @@ func benchmarkSequenceAlgos<S: Sequence>(s: S, n: Int) where S.Element == Int {
CheckResults(s.starts(with: s))
}

let n = 10_000
let n = 1_000
let r = 0..<(n*100)
let l = List(0..<n)
let c = ContiguousArray(0..<(n*100))
let a = Array(0..<(n*100))
let y = AnySequence(0..<n)
let y = AnySequence(0..<n/10)
let s = sequence(first: 0, next: { $0 < n&-1 ? $0&+1 : nil})

func buildWorkload() {
blackHole(l.makeIterator())
blackHole(c.makeIterator())
blackHole(a.makeIterator())
blackHole(y.makeIterator())
blackHole(s.makeIterator())
}

func benchmarkEquatableSequenceAlgos<S: Sequence>(s: S, n: Int) where S.Element == Int, S: Equatable {
func benchmarkEquatableSequenceAlgos<S: Sequence>(s: S, n: Int)
where S.Element == Int, S: Equatable {
CheckResults(repeatElement(s, count: 1).contains(s))
CheckResults(!repeatElement(s, count: 1).contains { $0 != s })
}

@inline(never)
public func run_SequenceAlgosRange(_ N: Int) {
for _ in 0..<N {
benchmarkSequenceAlgos(s: r, n: r.count)
benchmarkEquatableSequenceAlgos(s: r, n: r.count)
}
}

@inline(never)
public func run_SequenceAlgosArray(_ N: Int) {
for _ in 0..<N {
benchmarkSequenceAlgos(s: a, n: a.count)
benchmarkEquatableSequenceAlgos(s: a, n: a.count)
}
}

@inline(never)
public func run_SequenceAlgosContiguousArray(_ N: Int) {
for _ in 0..<N {
benchmarkSequenceAlgos(s: c, n: c.count)
benchmarkEquatableSequenceAlgos(s: c, n: c.count)
}
}

@inline(never)
public func run_SequenceAlgosAnySequence(_ N: Int) {
for _ in 0..<N {
benchmarkSequenceAlgos(s: y, n: n)
}
}

@inline(never)
public func run_SequenceAlgosUnfoldSequence(_ N: Int) {
for _ in 0..<N {
benchmarkSequenceAlgos(s: s, n: n)
}
}

@inline(never)
public func run_SequenceAlgosList(_ N: Int) {
for _ in 0..<N {
benchmarkSequenceAlgos(s: l, n: n)
benchmarkEquatableSequenceAlgos(s: l, n: n)
}
}

enum List<Element> {
case end
indirect case node(Element, List<Element>)

init<S: BidirectionalCollection>(_ elements: S) where S.Element == Element {
self = elements.reversed().reduce(.end) { .node($1,$0) }
}
}

20 changes: 10 additions & 10 deletions benchmark/single-source/SetTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -296,29 +296,29 @@ public let SetTests = [
// Legacy benchmarks, kept for continuity with previous releases.
BenchmarkInfo(
name: "SetExclusiveOr", // ~"SetSymmetricDifferenceInt0"
runFunction: { n in run_SetSymmetricDifferenceInt(setAB, setCD, countABCD, 100 * n) },
runFunction: { n in run_SetSymmetricDifferenceInt(setAB, setCD, countABCD, 10 * n) },
tags: [.validation, .api, .Set],
setUpFunction: { blackHole([setAB, setCD]) }),
setUpFunction: { blackHole([setAB, setCD]) }, legacyFactor: 10),
BenchmarkInfo(
name: "SetExclusiveOr_OfObjects", // ~"SetSymmetricDifferenceBox0"
runFunction: { n in run_SetSymmetricDifferenceBox(setOAB, setOCD, countABCD, 100 * n) },
runFunction: { n in run_SetSymmetricDifferenceBox(setOAB, setOCD, countABCD, 10 * n) },
tags: [.validation, .api, .Set],
setUpFunction: { blackHole([setOAB, setOCD]) }),
setUpFunction: { blackHole([setOAB, setOCD]) }, legacyFactor: 10),
BenchmarkInfo(
name: "SetIntersect", // ~"SetIntersectionInt0"
runFunction: { n in run_SetIntersectionInt(setAB, setCD, 0, 100 * n) },
runFunction: { n in run_SetIntersectionInt(setAB, setCD, 0, 10 * n) },
tags: [.validation, .api, .Set],
setUpFunction: { blackHole([setAB, setCD]) }),
setUpFunction: { blackHole([setAB, setCD]) }, legacyFactor: 10),
BenchmarkInfo(
name: "SetUnion", // ~"SetUnionInt0"
runFunction: { n in run_SetUnionInt(setAB, setCD, countABCD, 100 * n) },
runFunction: { n in run_SetUnionInt(setAB, setCD, countABCD, 10 * n) },
tags: [.validation, .api, .Set],
setUpFunction: { blackHole([setAB, setCD]) }),
setUpFunction: { blackHole([setAB, setCD]) }, legacyFactor: 10),
BenchmarkInfo(
name: "SetUnion_OfObjects", // ~"SetUnionBox0"
runFunction: { n in run_SetUnionBox(setOAB, setOCD, countABCD, 100 * n) },
runFunction: { n in run_SetUnionBox(setOAB, setOCD, countABCD, 10 * n) },
tags: [.validation, .api, .Set],
setUpFunction: { blackHole([setOAB, setOCD]) }),
setUpFunction: { blackHole([setOAB, setOCD]) }, legacyFactor: 10),
]

@inline(never)
Expand Down
10 changes: 6 additions & 4 deletions benchmark/single-source/SortIntPyramids.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ public let SortIntPyramids = [
BenchmarkInfo(
name: "SortIntPyramid",
runFunction: run_SortIntPyramid,
tags: [.validation, .api, .algorithm]),
tags: [.validation, .api, .algorithm],
legacyFactor: 5),
BenchmarkInfo(
name: "SortAdjacentIntPyramids",
runFunction: run_SortAdjacentIntPyramids,
tags: [.validation, .api, .algorithm]),
tags: [.validation, .api, .algorithm],
legacyFactor: 5),
]

// let A - array sorted in ascending order,
Expand Down Expand Up @@ -51,7 +53,7 @@ let adjacentPyramidsTemplate: [Int] = (1...aPH) + (1...aPH).reversed()

@inline(never)
public func run_SortIntPyramid(_ N: Int) {
for _ in 1...25*N {
for _ in 1...5*N {
var pyramid = pyramidTemplate

// sort pyramid in place.
Expand All @@ -64,7 +66,7 @@ public func run_SortIntPyramid(_ N: Int) {

@inline(never)
public func run_SortAdjacentIntPyramids(_ N: Int) {
for _ in 1...25*N {
for _ in 1...5*N {
var adjacentPyramids = adjacentPyramidsTemplate
adjacentPyramids.sort()
// Check whether pyramid is sorted.
Expand Down
5 changes: 3 additions & 2 deletions benchmark/single-source/SortLargeExistentials.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import TestsUtils
public let SortLargeExistentials = BenchmarkInfo(
name: "SortLargeExistentials",
runFunction: run_SortLargeExistentials,
tags: [.validation, .api, .algorithm])
tags: [.validation, .api, .algorithm],
legacyFactor: 100)

protocol LetterKind {
var value: String { get }
Expand Down Expand Up @@ -74,7 +75,7 @@ let lettersTemplate : [LetterKind] = [

@inline(never)
public func run_SortLargeExistentials(_ N: Int) {
for _ in 1...100*N {
for _ in 1...N {
var letters = lettersTemplate

letters.sort {
Expand Down
14 changes: 9 additions & 5 deletions benchmark/single-source/SortStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@
//===----------------------------------------------------------------------===//
import TestsUtils

let t: [BenchmarkCategory] = [.validation, .api, .algorithm, .String]
// Sort an array of strings using an explicit sort predicate.
public let SortStrings = [
BenchmarkInfo(name: "SortSortedStrings", runFunction: run_SortSortedStrings, tags: [.validation, .api, .algorithm, .String],
BenchmarkInfo(name: "SortSortedStrings",
runFunction: run_SortSortedStrings, tags: t,
setUpFunction: { blackHole(sortedWords) }),
BenchmarkInfo(name: "SortStrings", runFunction: run_SortStrings, tags: [.validation, .api, .algorithm, .String],
BenchmarkInfo(name: "SortStrings",
runFunction: run_SortStrings, tags: t,
setUpFunction: { blackHole(words) }),
BenchmarkInfo(name: "SortStringsUnicode", runFunction: run_SortStringsUnicode, tags: [.validation, .api, .algorithm, .String],
setUpFunction: { blackHole(unicodeWords) }),
BenchmarkInfo(name: "SortStringsUnicode",
runFunction: run_SortStringsUnicode, tags: t,
setUpFunction: { blackHole(unicodeWords) }, legacyFactor: 5),
]

let sortedWords = words.sorted()
Expand Down Expand Up @@ -2050,7 +2054,7 @@ var unicodeWords: [String] = [
]

public func run_SortStringsUnicode(_ N: Int) {
for _ in 1...5*N {
for _ in 1...N {
benchSortStrings(unicodeWords)
}
}
14 changes: 4 additions & 10 deletions benchmark/single-source/StackPromo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import TestsUtils
public let StackPromo = BenchmarkInfo(
name: "StackPromo",
runFunction: run_StackPromo,
tags: [.regression])
tags: [.regression],
legacyFactor: 100)

protocol Proto {
func at() -> Int
Expand Down Expand Up @@ -43,19 +44,12 @@ class Foo : Proto {
@inline(never)
func work(_ f: Foo) -> Int {
var r = 0
for _ in 0..<100_000 {
for _ in 0..<1_000 {
r += testStackAllocation(f)
}
return r
}

@inline(never)
func hole(_ use: Int, _ N: Int) {
if (N == 0) {
print("use: \(use)")
}
}

public func run_StackPromo(_ N: Int) {
let foo = Foo()
var r = 0
Expand All @@ -66,5 +60,5 @@ public func run_StackPromo(_ N: Int) {
r -= work(foo)
}
}
hole(r, N)
blackHole(r)
}
5 changes: 3 additions & 2 deletions benchmark/single-source/TwoSum.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import TestsUtils
public let TwoSum = BenchmarkInfo(
name: "TwoSum",
runFunction: run_TwoSum,
tags: [.validation, .api, .Dictionary, .Array, .algorithm])
tags: [.validation, .api, .Dictionary, .Array, .algorithm],
legacyFactor: 2)

let array = [
959, 81, 670, 727, 416, 171, 401, 398, 707, 596, 200, 9, 414, 98, 43,
Expand Down Expand Up @@ -61,7 +62,7 @@ public func run_TwoSum(_ N: Int) {
var i1: Int?
var i2: Int?
var Dict: Dictionary<Int, Int> = [:]
for _ in 1...2*N {
for _ in 1...N {
for Sum in 500..<600 {
Dict = [:]
i1 = nil
Expand Down
Loading