Skip to content

[benchmark] Janitor Duty: Sweep Quadratic #22673

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 3 commits into from
Feb 20, 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
1 change: 0 additions & 1 deletion benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ set(SWIFT_BENCH_MODULES
single-source/FloatingPointPrinting
single-source/Hanoi
single-source/Hash
single-source/HashQuadratic
single-source/Histogram
single-source/InsertCharacter
single-source/Integrate
Expand Down
88 changes: 38 additions & 50 deletions benchmark/single-source/DictionaryCopy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,66 +17,54 @@

import TestsUtils

public let DictionaryCopy = [
BenchmarkInfo(name: "DictionaryCopy", runFunction: run_DictionaryCopy,
tags: [.validation, .api, .Dictionary]),
BenchmarkInfo(name: "DictionaryFilter", runFunction: run_DictionaryFilter,
tags: [.validation, .api, .Dictionary]),
]
let t: [BenchmarkCategory] = [.validation, .api, .Dictionary]

@inline(never)
public func testCopy(_ size: Int) {
var dict1 = [Int: Int](minimumCapacity: size)
// We run the test at a spread of sizes between 1*x and 2*x, because the
// quadratic behavior only happens at certain load factors.

// Fill dictionary
for i in 1...size {
dict1[i] = 2 * i
}
CheckResults(dict1.count == size)
public let DictionaryCopy = [
BenchmarkInfo(name:"Dict.CopyKeyValue.16k",
runFunction: copyKeyValue, tags: t, setUpFunction: { dict(16_000) }),
BenchmarkInfo(name:"Dict.CopyKeyValue.20k",
runFunction: copyKeyValue, tags: t, setUpFunction: { dict(20_000) }),
BenchmarkInfo(name:"Dict.CopyKeyValue.24k",
runFunction: copyKeyValue, tags: t, setUpFunction: { dict(24_000) }),
BenchmarkInfo(name:"Dict.CopyKeyValue.28k",
runFunction: copyKeyValue, tags: t, setUpFunction: { dict(28_000) }),

var dict2 = [Int: Int]()
for (key, value) in dict1 {
dict2[key] = value
}
CheckResults(dict2.count == size)
}
BenchmarkInfo(name:"Dict.FilterAllMatch.16k",
runFunction: filterAllMatch, tags: t, setUpFunction: { dict(16_000) }),
BenchmarkInfo(name:"Dict.FilterAllMatch.20k",
runFunction: filterAllMatch, tags: t, setUpFunction: { dict(20_000) }),
BenchmarkInfo(name:"Dict.FilterAllMatch.24k",
runFunction: filterAllMatch, tags: t, setUpFunction: { dict(24_000) }),
BenchmarkInfo(name:"Dict.FilterAllMatch.28k",
runFunction: filterAllMatch, tags: t, setUpFunction: { dict(28_000) }),
]

@inline(never)
public func run_DictionaryCopy(_ N: Int) {
for _ in 0 ..< N {
// We run the test at a spread of sizes between 1*x and 2*x, because the
// quadratic behavior only happens at certain load factors.
testCopy(100_000)
testCopy(125_000)
testCopy(150_000)
testCopy(175_000)
}
var dict: [Int: Int]?

func dict(_ size: Int) {
dict = Dictionary(uniqueKeysWithValues: zip(1...size, 1...size))
}

@inline(never)
public func testFilter(_ size: Int) {
var dict1 = [Int: Int](minimumCapacity: size)

// Fill dictionary
for i in 1...size {
dict1[i] = 2 * i
func copyKeyValue(N: Int) {
for _ in 1...N {
var copy = [Int: Int]()
for (key, value) in dict! {
copy[key] = value
}
CheckResults(copy.count == dict!.count)
}
CheckResults(dict1.count == size)

// Filter with a predicate returning true is essentially the same loop as the
// one in testCopy above.
let dict2 = dict1.filter { _ in true }
CheckResults(dict2.count == size)
}

// Filter with a predicate returning true is essentially the same loop as the
// one in copyKeyValue above.
@inline(never)
public func run_DictionaryFilter(_ N: Int) {
for _ in 0 ..< N {
// We run the test at a spread of sizes between 1*x and 2*x, because the
// quadratic behavior only happens at certain load factors.
testFilter(100_000)
testFilter(125_000)
testFilter(150_000)
testFilter(175_000)
func filterAllMatch(N: Int) {
for _ in 1...N {
let copy = dict!.filter { _ in true }
CheckResults(copy.count == dict!.count)
}
}
37 changes: 0 additions & 37 deletions benchmark/single-source/HashQuadratic.swift

This file was deleted.

2 changes: 0 additions & 2 deletions benchmark/utils/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ import FlattenList
import FloatingPointPrinting
import Hanoi
import Hash
import HashQuadratic
import Histogram
import InsertCharacter
import Integrate
Expand Down Expand Up @@ -249,7 +248,6 @@ registerBenchmark(FlattenListFlatMap)
registerBenchmark(FloatingPointPrinting)
registerBenchmark(Hanoi)
registerBenchmark(HashTest)
registerBenchmark(HashQuadratic)
registerBenchmark(Histogram)
registerBenchmark(InsertCharacter)
registerBenchmark(IntegrateTest)
Expand Down
21 changes: 11 additions & 10 deletions test/benchmark/Benchmark_O.test.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ as a verification of this public API to prevent its accidental breakage.
[BD]: https://github.com/apple/swift/blob/master/benchmark/scripts/Benchmark_Driver
[Testing]: https://github.com/apple/swift/blob/master/docs/Testing.md

Note: Following tests use *HashQuadratic* as an example of a benchmark that is
excluded from the default "pre-commit" list because it is marked `unstable` and
the default skip-tags (`unstable,skip`) will exclude it. The *Ackermann* and
Note: Following tests use *Existential.* as an example of a benchmarks that are
excluded from the default "pre-commit" list because they are marked `skip` and
the default skip-tags (`unstable,skip`) will exclude them. The *Ackermann* and
*AngryPhonebook* are alphabetically the first two benchmarks in the test suite
(used to verify running by index). If these assumptions change, the test must be
adapted.
Expand All @@ -27,22 +27,22 @@ RUN: %Benchmark_O --list | %FileCheck %s \
RUN: --check-prefix LISTPRECOMMIT \
RUN: --check-prefix LISTTAGS
LISTPRECOMMIT: #,Test,[Tags]
LISTPRECOMMIT-NOT: HashQuadratic
LISTPRECOMMIT-NOT: Existential.
LISTPRECOMMIT: {{[0-9]+}},AngryPhonebook
LISTTAGS-SAME: ,[
LISTTAGS-NOT: TestsUtils.BenchmarkCategory.
LISTTAGS-SAME: String, api, validation
LISTTAGS-SAME: ]
````

Verify HashQuadratic is listed when skip-tags are explicitly empty and that it
is marked unstable:
Verify `Existential.` benchmarks are listed when skip-tags are explicitly empty
and that they are marked `skip`:

````
RUN: %Benchmark_O --list --skip-tags= | %FileCheck %s --check-prefix LISTALL
LISTALL: AngryPhonebook
LISTALL: HashQuadratic
LISTALL-SAME: unstable
LISTALL: Existential.
LISTALL-SAME: skip
````

## Benchmark Selection
Expand All @@ -54,8 +54,9 @@ It provides us with ability to do a "dry run".
Run benchmark by name (even if its tags match the skip-tags) or test number:

````
RUN: %Benchmark_O HashQuadratic --list | %FileCheck %s --check-prefix NAMEDSKIP
NAMEDSKIP: HashQuadratic
RUN: %Benchmark_O Existential.Mutating.Ref1 --list \
RUN: | %FileCheck %s --check-prefix NAMEDSKIP
NAMEDSKIP: Existential.Mutating.Ref1

RUN: %Benchmark_O 1 --list | %FileCheck %s --check-prefix RUNBYNUMBER
RUNBYNUMBER: Ackermann
Expand Down