Merge pull request #39336 from lorentey/decapitate-benchmarks

[benchmark][NFC] Use Swift naming conventions
This commit is contained in:
Karoy Lorentey
2021-09-20 17:16:35 -07:00
committed by GitHub
188 changed files with 3260 additions and 3145 deletions

View File

@@ -59,7 +59,7 @@ set(SWIFT_BENCH_MODULES
single-source/CharacterProperties
single-source/Chars
single-source/ClassArrayGetter
single-source/Codable
single-source/CodableTest
single-source/Combos
single-source/DataBenchmarks
single-source/DeadArray
@@ -76,7 +76,7 @@ set(SWIFT_BENCH_MODULES
single-source/DictionaryCopy
single-source/DictionaryGroup
single-source/DictionaryKeysContains
single-source/DictionaryLiteral
single-source/DictionaryLiteralTest
single-source/DictionaryOfAnyHashableStrings
single-source/DictionaryRemove
single-source/DictionarySubscriptDefault
@@ -112,11 +112,11 @@ set(SWIFT_BENCH_MODULES
single-source/LuhnAlgoLazy
single-source/MapReduce
single-source/Memset
single-source/Mirror
single-source/MirrorTest
single-source/MonteCarloE
single-source/MonteCarloPi
single-source/NSDictionaryCastToSwift
single-source/NSError
single-source/NSErrorTest
single-source/NSStringConversion
single-source/NibbleSort
single-source/NIOChannelPipeline
@@ -143,7 +143,7 @@ set(SWIFT_BENCH_MODULES
single-source/ProtocolConformance
single-source/ProtocolDispatch
single-source/ProtocolDispatch2
single-source/Queue
single-source/QueueTest
single-source/RC4
single-source/RGBHistogram
single-source/Radix2CooleyTukey
@@ -186,7 +186,7 @@ set(SWIFT_BENCH_MODULES
single-source/StringSwitch
single-source/StringTests
single-source/StringWalk
single-source/Substring
single-source/SubstringTest
single-source/Suffix
single-source/SuperChars
single-source/TwoSum

View File

@@ -313,16 +313,18 @@ If needed you can multiply N by a fixed amount (e.g. `1...100*N`) to achieve thi
// rdar://problem/00000000
import TestsUtils
public let YourTestName = BenchmarkInfo(
name: "YourTestName",
runFunction: run_YourTestName,
tags: [.regression])
public let benchmarks = [
BenchmarkInfo(
name: "YourTestName",
runFunction: run_YourTestName,
tags: [.regression])
]
@inline(never)
public func run_YourTestName(N: Int) {
public func run_YourTestName(n: Int) {
# Declare variables
for i in 1...N {
for i in 1...n {
# Perform work
# Verify work was done; break otherwise

View File

@@ -16,14 +16,16 @@
import TestsUtils
import CxxCreateObjects
public let CreateObjects = BenchmarkInfo(
name: "CreateObjects",
runFunction: run_CreateObjects,
tags: [.validation, .bridging])
public let benchmarks = [
BenchmarkInfo(
name: "CreateObjects",
runFunction: run_CreateObjects,
tags: [.validation, .bridging])
]
@inline(never)
public func run_CreateObjects(_ N: Int) {
for i in 0...(N * 10_000) {
public func run_CreateObjects(_ n: Int) {
for i in 0...(n * 10_000) {
let x = Int32(i)
let f = CxxLoadableIntWrapper(value: x)
blackHole(f)

View File

@@ -70,7 +70,7 @@ class PriorityQueue {
while (ind != 0) {
let p = getParentIndex(ind)
if heap[p].cost > c {
Swap(p, with: ind)
swap(p, with: ind)
ind = p
} else {
break
@@ -83,7 +83,7 @@ class PriorityQueue {
if (heap.isEmpty) {
return nil
}
Swap(0, with:heap.count-1)
swap(0, with:heap.count-1)
let r = heap.removeLast()
graphIndexToHeapIndexMap[r.to] = nil
bubbleDown(0)
@@ -111,21 +111,21 @@ class PriorityQueue {
if (heap[ind].cost <= heap[min].cost) {
break
}
Swap(ind, with: min)
swap(ind, with: min)
ind = min
}
}
// Swaps elements I and J in the heap and correspondingly updates
// graphIndexToHeapIndexMap.
func Swap(_ i: Int, with j : Int) {
func swap(_ i: Int, with j : Int) {
if (i == j) {
return
}
(heap[i], heap[j]) = (heap[j], heap[i])
let (I, J) = (heap[i].to, heap[j].to)
(graphIndexToHeapIndexMap[I], graphIndexToHeapIndexMap[J]) =
(graphIndexToHeapIndexMap[J], graphIndexToHeapIndexMap[I])
let (i2, j2) = (heap[i].to, heap[j].to)
(graphIndexToHeapIndexMap[i2], graphIndexToHeapIndexMap[j2]) =
(graphIndexToHeapIndexMap[j2], graphIndexToHeapIndexMap[i2])
}
// Dumps the heap.
@@ -182,7 +182,7 @@ extension Edge : Hashable {
}
}
func Prims(_ graph : Array<GraphNode>, _ fun : (Int, Int) -> Double) -> Array<Int?> {
func prims(_ graph : Array<GraphNode>, _ fun : (Int, Int) -> Double) -> Array<Int?> {
var treeEdges = Array<Int?>(repeating:nil, count:graph.count)
let queue = PriorityQueue(Num:graph.count)

View File

@@ -12,15 +12,17 @@
import TestsUtils
public let PrimsSplit = BenchmarkInfo(
name: "PrimsSplit",
runFunction: run_PrimsSplit,
tags: [.validation, .algorithm],
legacyFactor: 5)
public let benchmarks = [
BenchmarkInfo(
name: "PrimsSplit",
runFunction: run_PrimsSplit,
tags: [.validation, .algorithm],
legacyFactor: 5)
]
@inline(never)
public func run_PrimsSplit(_ N: Int) {
for _ in 1...N {
public func run_PrimsSplit(_ n: Int) {
for _ in 1...n {
let nodes : [Int] = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
@@ -547,7 +549,7 @@ public func run_PrimsSplit(_ N: Int) {
}
// Find spanning tree
let treeEdges = Prims(graph, { (start: Int, end: Int) in
let treeEdges = prims(graph, { (start: Int, end: Int) in
return map[Edge(start: start, end: end)]!
})
@@ -556,6 +558,6 @@ public func run_PrimsSplit(_ N: Int) {
for i in 1..<treeEdges.count {
if let n = treeEdges[i] { cost += map[Edge(start: n, end: i)]! }
}
CheckResults(Int(cost) == 49324)
check(Int(cost) == 49324)
}
}

View File

@@ -17,6 +17,6 @@ public let {name} = [
]
@inline(never)
public func run_{name}(N: Int) {{
public func run_{name}(n: Int) {{
// TODO
}}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -14,38 +14,39 @@
// for performance measuring.
import TestsUtils
public let Ackermann = BenchmarkInfo(
name: "Ackermann",
runFunction: run_Ackermann,
tags: [.algorithm])
public let benchmarks =
BenchmarkInfo(
name: "Ackermann",
runFunction: run_Ackermann,
tags: [.algorithm])
func ackermann(_ M: Int, _ N : Int) -> Int {
if (M == 0) { return N + 1 }
if (N == 0) { return ackermann(M - 1, 1) }
return ackermann(M - 1, ackermann(M, N - 1))
func _ackermann(_ m: Int, _ n : Int) -> Int {
if (m == 0) { return n + 1 }
if (n == 0) { return _ackermann(m - 1, 1) }
return _ackermann(m - 1, _ackermann(m, n - 1))
}
@inline(never)
func Ackermann(_ M: Int, _ N : Int) -> Int {
func ackermann(_ m: Int, _ n : Int) -> Int {
// This if prevents optimizer from computing return value of Ackermann(3,9)
// at compile time.
if False() { return 0 }
if (M == 0) { return N + 1 }
if (N == 0) { return ackermann(M - 1, 1) }
return ackermann(M - 1, ackermann(M, N - 1))
if getFalse() { return 0 }
if (m == 0) { return n + 1 }
if (n == 0) { return _ackermann(m - 1, 1) }
return _ackermann(m - 1, _ackermann(m, n - 1))
}
let ref_result = [5, 13, 29, 61, 125, 253, 509, 1021, 2045, 4093, 8189, 16381, 32765, 65533, 131069]
@inline(never)
public func run_Ackermann(_ N: Int) {
public func run_Ackermann(_ n: Int) {
let (m, n) = (3, 6)
var result = 0
for _ in 1...N {
result = Ackermann(m, n)
for _ in 1...n {
result = ackermann(m, n)
if result != ref_result[n] {
break
}
}
CheckResults(result == ref_result[n])
check(result == ref_result[n])
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -16,7 +16,7 @@ import TestsUtils
let t: [BenchmarkCategory] = [.validation, .api, .String]
public let AngryPhonebook = [
public let benchmarks = [
BenchmarkInfo(
name: "AngryPhonebook",
runFunction: run_AngryPhonebook,
@@ -76,9 +76,9 @@ let words = [
"Nicholas", "Eric", "Stephen", "Jacob", "Larry", "Frank"]
@inline(never)
public func run_AngryPhonebook(_ N: Int) {
public func run_AngryPhonebook(_ n: Int) {
// Permute the names.
for _ in 1...N {
for _ in 1...n {
for firstname in words {
for lastname in words {
_ = (firstname.uppercased(), lastname.lowercased())
@@ -132,10 +132,10 @@ let longArmenian = phonebook(armenian)
let longCyrillic = phonebook(cyrillic)
@inline(never)
public func angryPhonebook(_ N: Int, _ names: [String]) {
public func angryPhonebook(_ n: Int, _ names: [String]) {
assert(names.count == 20)
// Permute the names.
for _ in 1...N {
for _ in 1...n {
for firstname in names {
for lastname in names {
blackHole((firstname.uppercased(), lastname.lowercased()))
@@ -145,8 +145,8 @@ public func angryPhonebook(_ N: Int, _ names: [String]) {
}
@inline(never)
public func angryPhonebook(_ N: Int, precomposed names: String) {
for _ in 1...N {
public func angryPhonebook(_ n: Int, precomposed names: String) {
for _ in 1...n {
blackHole((names.uppercased(), names.lowercased()))
}
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -22,12 +22,13 @@ import TestsUtils
// 11% _swift_stdlib_makeAnyHashableUpcastingToHashableBaseType
// 16% _swift_retain_[n]
// 5% swift_conformsToProtocol
public let AnyHashableWithAClass = BenchmarkInfo(
name: "AnyHashableWithAClass",
runFunction: run_AnyHashableWithAClass,
tags: [.abstraction, .runtime, .cpubench],
legacyFactor: 500
)
public let benchmarks =
BenchmarkInfo(
name: "AnyHashableWithAClass",
runFunction: run_AnyHashableWithAClass,
tags: [.abstraction, .runtime, .cpubench],
legacyFactor: 500
)
class TestHashableBase : Hashable {
var value: Int
@@ -54,9 +55,9 @@ class TestHashableDerived4 : TestHashableDerived3 {}
class TestHashableDerived5 : TestHashableDerived4 {}
@inline(never)
public func run_AnyHashableWithAClass(_ N: Int) {
public func run_AnyHashableWithAClass(_ n: Int) {
let c = TestHashableDerived5(10)
for _ in 0...(N*1000) {
for _ in 0...(n*1000) {
_ = AnyHashable(c)
}
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -12,38 +12,39 @@
import TestsUtils
public let Array2D = BenchmarkInfo(
name: "Array2D",
runFunction: run_Array2D,
tags: [.validation, .api, .Array],
setUpFunction: { blackHole(inputArray) },
tearDownFunction: { inputArray = nil },
legacyFactor: 16)
public let benchmarks =
BenchmarkInfo(
name: "Array2D",
runFunction: run_Array2D,
tags: [.validation, .api, .Array],
setUpFunction: { blackHole(inputArray) },
tearDownFunction: { inputArray = nil },
legacyFactor: 16)
let size = 256
var inputArray: [[Int]]! = {
var A: [[Int]] = []
A.reserveCapacity(size)
var a: [[Int]] = []
a.reserveCapacity(size)
for _ in 0 ..< size {
A.append(Array(0 ..< size))
a.append(Array(0 ..< size))
}
return A
return a
}()
@inline(never)
func modifyArray(_ A: inout [[Int]], _ N: Int) {
for _ in 0..<N {
func modifyArray(_ a: inout [[Int]], _ n: Int) {
for _ in 0..<n {
for i in 0 ..< size {
for y in 0 ..< size {
A[i][y] = A[i][y] + 1
A[i][y] = A[i][y] - 1
a[i][y] = a[i][y] + 1
a[i][y] = a[i][y] - 1
}
}
}
}
@inline(never)
public func run_Array2D(_ N: Int) {
modifyArray(&inputArray, N)
public func run_Array2D(_ n: Int) {
modifyArray(&inputArray, n)
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -15,7 +15,7 @@
import TestsUtils
let t: [BenchmarkCategory] = [.validation, .api, .Array]
public let ArrayAppend = [
public let benchmarks = [
BenchmarkInfo(name: "ArrayAppend", runFunction: run_ArrayAppend, tags: t, legacyFactor: 10),
BenchmarkInfo(name: "ArrayAppendArrayOfInt", runFunction: run_ArrayAppendArrayOfInt, tags: t,
setUpFunction: ones, tearDownFunction: releaseOnes, legacyFactor: 10),
@@ -63,8 +63,8 @@ func releaseOnes() { otherOnes = nil }
// Append single element
@inline(never)
public func run_ArrayAppend(_ N: Int) {
for _ in 0..<N {
public func run_ArrayAppend(_ n: Int) {
for _ in 0..<n {
var nums = [Int]()
for _ in 0..<40000 {
nums.append(1)
@@ -74,8 +74,8 @@ public func run_ArrayAppend(_ N: Int) {
// Append single element with reserve
@inline(never)
public func run_ArrayAppendReserved(_ N: Int) {
for _ in 0..<N {
public func run_ArrayAppendReserved(_ n: Int) {
for _ in 0..<n {
var nums = [Int]()
nums.reserveCapacity(40000)
for _ in 0..<40000 {
@@ -87,10 +87,10 @@ public func run_ArrayAppendReserved(_ N: Int) {
// Append a sequence. Length of sequence unknown so
// can't pre-reserve capacity.
@inline(never)
public func run_ArrayAppendSequence(_ N: Int) {
public func run_ArrayAppendSequence(_ n: Int) {
let seq = stride(from: 0, to: 10_000, by: 1)
for _ in 0..<N {
for _ in 0..<n {
var nums = [Int]()
for _ in 0..<8 {
nums.append(contentsOf: seq)
@@ -101,10 +101,10 @@ public func run_ArrayAppendSequence(_ N: Int) {
// Append another array. Length of sequence known so
// can pre-reserve capacity.
@inline(never)
public func run_ArrayAppendArrayOfInt(_ N: Int) {
public func run_ArrayAppendArrayOfInt(_ n: Int) {
let other: [Int] = otherOnes
for _ in 0..<N {
for _ in 0..<n {
var nums = [Int]()
for _ in 0..<8 {
nums.append(contentsOf: other)
@@ -115,10 +115,10 @@ public func run_ArrayAppendArrayOfInt(_ N: Int) {
// Identical to run_ArrayAppendArrayOfInt
// except +=, to check equally performant.
@inline(never)
public func run_ArrayPlusEqualArrayOfInt(_ N: Int) {
public func run_ArrayPlusEqualArrayOfInt(_ n: Int) {
let other: [Int] = otherOnes
for _ in 0..<N {
for _ in 0..<n {
var nums = [Int]()
for _ in 0..<8 {
nums += other
@@ -129,10 +129,10 @@ public func run_ArrayPlusEqualArrayOfInt(_ N: Int) {
// Append another array. Length of sequence known so
// can pre-reserve capacity.
@inline(never)
public func run_ArrayAppendStrings(_ N: Int) {
public func run_ArrayAppendStrings(_ n: Int) {
let other: [String] = otherStrings
for _ in 0..<N {
for _ in 0..<n {
var nums = [String]()
// lower inner count due to string slowness
for _ in 0..<4 {
@@ -149,10 +149,10 @@ struct S<T,U> {
// Append another array. Length of sequence known so
// can pre-reserve capacity.
@inline(never)
public func run_ArrayAppendGenericStructs(_ N: Int) {
public func run_ArrayAppendGenericStructs(_ n: Int) {
let other: [S<Int, Double>] = otherStructs
for _ in 0..<N {
for _ in 0..<n {
var nums = [S<Int,Double>]()
for _ in 0..<8 {
nums += other
@@ -163,10 +163,10 @@ public func run_ArrayAppendGenericStructs(_ N: Int) {
// Append another array. Length of sequence known so
// can pre-reserve capacity.
@inline(never)
public func run_ArrayAppendOptionals(_ N: Int) {
public func run_ArrayAppendOptionals(_ n: Int) {
let other: [Int?] = otherOptionalOnes
for _ in 0..<N {
for _ in 0..<n {
var nums = [Int?]()
for _ in 0..<8 {
nums += other
@@ -178,10 +178,10 @@ public func run_ArrayAppendOptionals(_ N: Int) {
// Append a lazily-mapped array. Length of sequence known so
// can pre-reserve capacity, but no optimization points used.
@inline(never)
public func run_ArrayAppendLazyMap(_ N: Int) {
public func run_ArrayAppendLazyMap(_ n: Int) {
let other = array.lazy.map { $0 * 2 }
for _ in 0..<N {
for _ in 0..<n {
var nums = [Int]()
for _ in 0..<8 {
nums += other
@@ -193,10 +193,10 @@ public func run_ArrayAppendLazyMap(_ N: Int) {
// Append a Repeat collection. Length of sequence known so
// can pre-reserve capacity, but no optimization points used.
@inline(never)
public func run_ArrayAppendRepeatCol(_ N: Int) {
public func run_ArrayAppendRepeatCol(_ n: Int) {
let other = repeatElement(1, count: 10_000)
for _ in 0..<N {
for _ in 0..<n {
var nums = [Int]()
for _ in 0..<8 {
nums += other
@@ -214,10 +214,10 @@ public func appendFromGeneric<
}
@inline(never)
public func run_ArrayAppendFromGeneric(_ N: Int) {
public func run_ArrayAppendFromGeneric(_ n: Int) {
let other: [Int] = otherOnes
for _ in 0..<N {
for _ in 0..<n {
var nums = [Int]()
for _ in 0..<8 {
appendFromGeneric(array: &nums, sequence: other)
@@ -234,10 +234,10 @@ public func appendToGeneric<
}
@inline(never)
public func run_ArrayAppendToGeneric(_ N: Int) {
public func run_ArrayAppendToGeneric(_ n: Int) {
let other: [Int] = otherOnes
for _ in 0..<N {
for _ in 0..<n {
var nums = [Int]()
for _ in 0..<8 {
appendToGeneric(collection: &nums, array: other)
@@ -256,10 +256,10 @@ where R.Element == S.Element {
}
@inline(never)
public func run_ArrayAppendToFromGeneric(_ N: Int) {
public func run_ArrayAppendToFromGeneric(_ n: Int) {
let other: [Int] = otherOnes
for _ in 0..<N {
for _ in 0..<n {
var nums = [Int]()
for _ in 0..<8 {
appendToFromGeneric(collection: &nums, sequence: other)
@@ -269,8 +269,8 @@ public func run_ArrayAppendToFromGeneric(_ N: Int) {
// Append a single element array with the += operator
@inline(never)
public func run_ArrayPlusEqualSingleElementCollection(_ N: Int) {
for _ in 0..<N {
public func run_ArrayPlusEqualSingleElementCollection(_ n: Int) {
for _ in 0..<n {
var nums = [Int]()
for _ in 0..<10_000 {
nums += [1]
@@ -280,8 +280,8 @@ public func run_ArrayPlusEqualSingleElementCollection(_ N: Int) {
// Append a five element array with the += operator
@inline(never)
public func run_ArrayPlusEqualFiveElementCollection(_ N: Int) {
for _ in 0..<N {
public func run_ArrayPlusEqualFiveElementCollection(_ n: Int) {
for _ in 0..<n {
var nums = [Int]()
for _ in 0..<10_000 {
nums += [1, 2, 3, 4, 5]
@@ -295,8 +295,8 @@ public func appendThreeElements(_ a: inout [Int]) {
}
@inline(never)
public func run_ArrayPlusEqualThreeElements(_ N: Int) {
for _ in 0..<(1_000 * N) {
public func run_ArrayPlusEqualThreeElements(_ n: Int) {
for _ in 0..<(1_000 * n) {
var a: [Int] = []
appendThreeElements(&a)
}
@@ -304,9 +304,9 @@ public func run_ArrayPlusEqualThreeElements(_ N: Int) {
// Append the utf8 elements of an ascii string to a [UInt8]
@inline(never)
public func run_ArrayAppendAscii(_ N: Int) {
public func run_ArrayAppendAscii(_ n: Int) {
let s = "the quick brown fox jumps over the lazy dog!"
for _ in 0..<N {
for _ in 0..<n {
var nums = [UInt8]()
for _ in 0..<3_000 {
nums += getString(s).utf8
@@ -316,9 +316,9 @@ public func run_ArrayAppendAscii(_ N: Int) {
// Append the utf8 elements of a latin1 string to a [UInt8]
@inline(never)
public func run_ArrayAppendLatin1(_ N: Int) {
public func run_ArrayAppendLatin1(_ n: Int) {
let s = "the quick brown fox jumps over the lazy dog\u{00A1}"
for _ in 0..<N {
for _ in 0..<n {
var nums = [UInt8]()
for _ in 0..<3_000 {
nums += getString(s).utf8
@@ -328,9 +328,9 @@ public func run_ArrayAppendLatin1(_ N: Int) {
// Append the utf8 elements of an utf16 string to a [UInt8]
@inline(never)
public func run_ArrayAppendUTF16(_ N: Int) {
public func run_ArrayAppendUTF16(_ n: Int) {
let s = "the quick brown 🦊 jumps over the lazy dog"
for _ in 0..<N {
for _ in 0..<n {
var nums = [UInt8]()
for _ in 0..<3_000 {
nums += getString(s).utf8
@@ -340,9 +340,9 @@ public func run_ArrayAppendUTF16(_ N: Int) {
// Append the utf8 elements of an ascii substring to a [UInt8]
@inline(never)
public func run_ArrayAppendAsciiSubstring(_ N: Int) {
public func run_ArrayAppendAsciiSubstring(_ n: Int) {
let s = "the quick brown fox jumps over the lazy dog!"[...]
for _ in 0..<N {
for _ in 0..<n {
var nums = [UInt8]()
for _ in 0..<3_000 {
nums += getSubstring(s).utf8
@@ -352,9 +352,9 @@ public func run_ArrayAppendAsciiSubstring(_ N: Int) {
// Append the utf8 elements of a latin1 substring to a [UInt8]
@inline(never)
public func run_ArrayAppendLatin1Substring(_ N: Int) {
public func run_ArrayAppendLatin1Substring(_ n: Int) {
let s = "the quick brown fox jumps over the lazy dog\u{00A1}"[...]
for _ in 0..<N {
for _ in 0..<n {
var nums = [UInt8]()
for _ in 0..<3_000 {
nums += getSubstring(s).utf8
@@ -364,9 +364,9 @@ public func run_ArrayAppendLatin1Substring(_ N: Int) {
// Append the utf8 elements of an utf16 substring to a [UInt8]
@inline(never)
public func run_ArrayAppendUTF16Substring(_ N: Int) {
public func run_ArrayAppendUTF16Substring(_ n: Int) {
let s = "the quick brown 🦊 jumps over the lazy dog"[...]
for _ in 0..<N {
for _ in 0..<n {
var nums = [UInt8]()
for _ in 0..<3_000 {
nums += getSubstring(s).utf8

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -11,7 +11,7 @@
//===----------------------------------------------------------------------===//
import TestsUtils
public let ArrayInClass = [
public let benchmarks = [
BenchmarkInfo(
name: "ArrayInClass",
runFunction: run_ArrayInClass,
@@ -22,7 +22,7 @@ public let ArrayInClass = [
BenchmarkInfo(name: "DistinctClassFieldAccesses",
runFunction: run_DistinctClassFieldAccesses,
tags: [.validation, .api, .Array],
setUpFunction: { workload = ClassWithArrs(N: 10_000) },
setUpFunction: { workload = ClassWithArrs(n: 10_000) },
tearDownFunction: { workload = nil }),
]
@@ -35,8 +35,8 @@ class ArrayContainer {
arr = [Int] (repeating: 0, count: 20_000)
}
func runLoop(_ N: Int) {
for _ in 0 ..< N {
func runLoop(_ n: Int) {
for _ in 0 ..< n {
for i in 0 ..< arr.count {
arr[i] = arr[i] + 1
}
@@ -45,41 +45,41 @@ class ArrayContainer {
}
@inline(never)
public func run_ArrayInClass(_ N: Int) {
public func run_ArrayInClass(_ n: Int) {
let a = ac!
a.runLoop(N)
a.runLoop(n)
}
class ClassWithArrs {
var N: Int = 0
var A: [Int]
var B: [Int]
var n: Int = 0
var a: [Int]
var b: [Int]
init(N: Int) {
self.N = N
init(n: Int) {
self.n = n
A = [Int](repeating: 0, count: N)
B = [Int](repeating: 0, count: N)
a = [Int](repeating: 0, count: n)
b = [Int](repeating: 0, count: n)
}
func readArr() {
for i in 0..<self.N {
guard A[i] == B[i] else { fatalError("") }
for i in 0..<self.n {
guard a[i] == b[i] else { fatalError("") }
}
}
func writeArr() {
for i in 0..<self.N {
A[i] = i
B[i] = i
for i in 0..<self.n {
a[i] = i
b[i] = i
}
}
}
var workload: ClassWithArrs!
public func run_DistinctClassFieldAccesses(_ N: Int) {
for _ in 1...N {
public func run_DistinctClassFieldAccesses(_ n: Int) {
for _ in 1...n {
workload.writeArr()
workload.readArr()
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -15,7 +15,7 @@
// It is reported to be slow: <rdar://problem/17297449>
import TestsUtils
public let ArrayLiteral = [
public let benchmarks = [
BenchmarkInfo(name: "ArrayLiteral2", runFunction: run_ArrayLiteral, tags: [.validation, .api, .Array]),
BenchmarkInfo(name: "ArrayValueProp", runFunction: run_ArrayValueProp, tags: [.validation, .api, .Array]),
BenchmarkInfo(name: "ArrayValueProp2", runFunction: run_ArrayValueProp2, tags: [.validation, .api, .Array]),
@@ -29,34 +29,34 @@ func makeArray() -> [Int] {
}
@inline(never)
public func run_ArrayLiteral(_ N: Int) {
for _ in 1...10000*N {
public func run_ArrayLiteral(_ n: Int) {
for _ in 1...10000*n {
blackHole(makeArray())
}
}
@inline(never)
func addLiteralArray() -> Int {
let Arr = [1, 2, 3]
return Arr[0] + Arr[1] + Arr[2]
let arr = [1, 2, 3]
return arr[0] + arr[1] + arr[2]
}
@inline(never)
public func run_ArrayValueProp(_ N: Int) {
public func run_ArrayValueProp(_ n: Int) {
var res = 123
for _ in 1...10000*N {
for _ in 1...10000*n {
res += addLiteralArray()
res -= addLiteralArray()
}
CheckResults(res == 123)
check(res == 123)
}
@inline(never)
func addLiteralArray2() -> Int {
let Arr = [1, 2, 3]
let arr = [1, 2, 3]
var r = 0
for elt in Arr {
for elt in arr {
r += elt
}
return r
@@ -64,50 +64,50 @@ func addLiteralArray2() -> Int {
@inline(never)
func addLiteralArray3() -> Int {
let Arr = [1, 2, 3]
let arr = [1, 2, 3]
var r = 0
for i in 0..<Arr.count {
r += Arr[i]
for i in 0..<arr.count {
r += arr[i]
}
return r
}
@inline(never)
func addLiteralArray4() -> Int {
let Arr = [1, 2, 3]
let arr = [1, 2, 3]
var r = 0
for i in 0..<3 {
r += Arr[i]
r += arr[i]
}
return r
}
@inline(never)
public func run_ArrayValueProp2(_ N: Int) {
public func run_ArrayValueProp2(_ n: Int) {
var res = 123
for _ in 1...10000*N {
for _ in 1...10000*n {
res += addLiteralArray2()
res -= addLiteralArray2()
}
CheckResults(res == 123)
check(res == 123)
}
@inline(never)
public func run_ArrayValueProp3(_ N: Int) {
public func run_ArrayValueProp3(_ n: Int) {
var res = 123
for _ in 1...10000*N {
for _ in 1...10000*n {
res += addLiteralArray3()
res -= addLiteralArray3()
}
CheckResults(res == 123)
check(res == 123)
}
@inline(never)
public func run_ArrayValueProp4(_ N: Int) {
public func run_ArrayValueProp4(_ n: Int) {
var res = 123
for _ in 1...10000*N {
for _ in 1...10000*n {
res += addLiteralArray4()
res -= addLiteralArray4()
}
CheckResults(res == 123)
check(res == 123)
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -20,7 +20,7 @@
import TestsUtils
public let ArrayOfGenericPOD = [
public let benchmarks = [
BenchmarkInfo(
// Renamed benchmark to "2" when IUO test was removed, which
// effectively changed what we're benchmarking here.
@@ -67,8 +67,8 @@ func genStructArray() {
}
@inline(never)
public func run_ArrayOfGenericPOD(_ N: Int) {
for _ in 0..<N {
public func run_ArrayOfGenericPOD(_ n: Int) {
for _ in 0..<n {
genEnumArray()
genStructArray()
}
@@ -91,8 +91,8 @@ func copyElements<S: Sequence>(_ contents: S) -> [UInt8]
}
@inline(never)
public func run_initFromSlice(_ N: Int) {
for _ in 0..<N {
public func run_initFromSlice(_ n: Int) {
for _ in 0..<n {
for _ in 0..<1000 {
// Slice off at least one element so the array buffer can't be reused.
blackHole(copyElements(globalArray[0..<4095]))

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -17,11 +17,12 @@
import TestsUtils
public let ArrayOfGenericRef = BenchmarkInfo(
name: "ArrayOfGenericRef",
runFunction: run_ArrayOfGenericRef,
tags: [.validation, .api, .Array],
legacyFactor: 10)
public let benchmarks =
BenchmarkInfo(
name: "ArrayOfGenericRef",
runFunction: run_ArrayOfGenericRef,
tags: [.validation, .api, .Array],
legacyFactor: 10)
protocol Constructible {
associatedtype Element
@@ -94,8 +95,8 @@ func genRefStructArray() {
}
@inline(never)
public func run_ArrayOfGenericRef(_ N: Int) {
for _ in 0..<N {
public func run_ArrayOfGenericRef(_ n: Int) {
for _ in 0..<n {
genPODRefArray()
genCommonRefArray()
genRefEnumArray()

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -18,10 +18,11 @@
import TestsUtils
public let ArrayOfPOD = BenchmarkInfo(
name: "ArrayOfPOD",
runFunction: run_ArrayOfPOD,
tags: [.validation, .api, .Array])
public let benchmarks =
BenchmarkInfo(
name: "ArrayOfPOD",
runFunction: run_ArrayOfPOD,
tags: [.validation, .api, .Array])
class RefArray<T> {
var array : [T]
@@ -60,8 +61,8 @@ func genStructArray() {
}
@inline(never)
public func run_ArrayOfPOD(_ N: Int) {
for _ in 0..<N {
public func run_ArrayOfPOD(_ n: Int) {
for _ in 0..<n {
genIntArray()
genEnumArray()
genStructArray()

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -18,11 +18,12 @@
import TestsUtils
public let ArrayOfRef = BenchmarkInfo(
name: "ArrayOfRef",
runFunction: run_ArrayOfRef,
tags: [.validation, .api, .Array],
legacyFactor: 10)
public let benchmarks =
BenchmarkInfo(
name: "ArrayOfRef",
runFunction: run_ArrayOfRef,
tags: [.validation, .api, .Array],
legacyFactor: 10)
protocol Constructible {
associatedtype Element
@@ -105,8 +106,8 @@ func genRefStructArray() {
}
@inline(never)
public func run_ArrayOfRef(_ N: Int) {
for _ in 0..<N {
public func run_ArrayOfRef(_ n: Int) {
for _ in 0..<n {
genPODRefArray()
genCommonRefArray()
genRefEnumArray()

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -15,11 +15,12 @@ import TestsUtils
// 33% isUniquelyReferenced
// 15% swift_rt_swift_isUniquelyReferencedOrPinned_nonNull_native
// 18% swift_isUniquelyReferencedOrPinned_nonNull_native
public let ArraySetElement = BenchmarkInfo(
name: "ArraySetElement",
runFunction: run_ArraySetElement,
tags: [.runtime, .cpubench]
)
public let benchmarks =
BenchmarkInfo(
name: "ArraySetElement",
runFunction: run_ArraySetElement,
tags: [.runtime, .cpubench]
)
// This is an effort to defeat isUniquelyReferenced optimization. Ideally
// microbenchmarks list this should be written in C.
@@ -28,9 +29,9 @@ func storeArrayElement(_ array: inout [Int], _ i: Int) {
array[i] = i
}
public func run_ArraySetElement(_ N: Int) {
public func run_ArraySetElement(_ n: Int) {
var array = [Int](repeating: 0, count: 10000)
for _ in 0..<10*N {
for _ in 0..<10*n {
for i in 0..<array.count {
storeArrayElement(&array, i)
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -13,26 +13,27 @@
// This test checks the performance of modifying an array element.
import TestsUtils
public let ArraySubscript = BenchmarkInfo(
name: "ArraySubscript",
runFunction: run_ArraySubscript,
tags: [.validation, .api, .Array],
legacyFactor: 4)
public let benchmarks =
BenchmarkInfo(
name: "ArraySubscript",
runFunction: run_ArraySubscript,
tags: [.validation, .api, .Array],
legacyFactor: 4)
@inline(never)
public func run_ArraySubscript(_ N: Int) {
SRand()
public func run_ArraySubscript(_ n: Int) {
var lfsr = LFSR()
let numArrays = 50
let numArrayElements = 100
func bound(_ x: Int) -> Int { return min(x, numArrayElements-1) }
for _ in 1...N {
for _ in 1...n {
var arrays = [[Int]](repeating: [], count: numArrays)
for i in 0..<numArrays {
for _ in 0..<numArrayElements {
arrays[i].append(Int(truncatingIfNeeded: Random()))
arrays[i].append(Int(truncatingIfNeeded: lfsr.next()))
}
}
@@ -41,6 +42,6 @@ public func run_ArraySubscript(_ N: Int) {
arrays[i][bound(i)] =
max(arrays[i-1][bound(i-1)], arrays[i][bound(i)])
}
CheckResults(arrays[0][0] <= arrays[numArrays-1][bound(numArrays-1)])
check(arrays[0][0] <= arrays[numArrays-1][bound(numArrays-1)])
}
}

View File

@@ -16,13 +16,15 @@
import TestsUtils
#if swift(>=4.2)
public let BinaryFloatingPointConversionFromBinaryInteger = BenchmarkInfo(
name: "BinaryFloatingPointConversionFromBinaryInteger",
runFunction: run_BinaryFloatingPointConversionFromBinaryInteger,
tags: [.validation, .algorithm]
)
public let benchmarks = [
BenchmarkInfo(
name: "BinaryFloatingPointConversionFromBinaryInteger",
runFunction: run_BinaryFloatingPointConversionFromBinaryInteger,
tags: [.validation, .algorithm]
),
]
#else
public let BinaryFloatingPointConversionFromBinaryInteger: [BenchmarkInfo] = []
public let benchmarks: [BenchmarkInfo] = []
#endif
struct MockBinaryInteger<T : BinaryInteger> {
@@ -196,17 +198,17 @@ extension MockBinaryInteger : BinaryInteger {
#if swift(>=4.2)
@inline(never)
public func run_BinaryFloatingPointConversionFromBinaryInteger(_ N: Int) {
public func run_BinaryFloatingPointConversionFromBinaryInteger(_ n: Int) {
var xs = [Double]()
xs.reserveCapacity(N)
for _ in 1...N {
xs.reserveCapacity(n)
for _ in 1...n {
var x = 0 as Double
for i in 0..<2000 {
x += Double._convert(from: MockBinaryInteger(getInt(i))).value
}
xs.append(x)
}
CheckResults(xs[getInt(0)] == 1999000)
check(xs[getInt(0)] == 1999000)
}
#endif

View File

@@ -12,62 +12,62 @@
import TestsUtils
public let BinaryFloatingPointPropertiesBinade = BenchmarkInfo(
name: "BinaryFloatingPointPropertiesBinade",
runFunction: run_BinaryFloatingPointPropertiesBinade,
tags: [.validation, .algorithm]
)
public let BinaryFloatingPointPropertiesNextUp = BenchmarkInfo(
name: "BinaryFloatingPointPropertiesNextUp",
runFunction: run_BinaryFloatingPointPropertiesNextUp,
tags: [.validation, .algorithm]
)
public let BinaryFloatingPointPropertiesUlp = BenchmarkInfo(
name: "BinaryFloatingPointPropertiesUlp",
runFunction: run_BinaryFloatingPointPropertiesUlp,
tags: [.validation, .algorithm]
)
public let benchmarks = [
BenchmarkInfo(
name: "BinaryFloatingPointPropertiesBinade",
runFunction: run_BinaryFloatingPointPropertiesBinade,
tags: [.validation, .algorithm]
),
BenchmarkInfo(
name: "BinaryFloatingPointPropertiesNextUp",
runFunction: run_BinaryFloatingPointPropertiesNextUp,
tags: [.validation, .algorithm]
),
BenchmarkInfo(
name: "BinaryFloatingPointPropertiesUlp",
runFunction: run_BinaryFloatingPointPropertiesUlp,
tags: [.validation, .algorithm]
)
]
@inline(never)
public func run_BinaryFloatingPointPropertiesBinade(_ N: Int) {
public func run_BinaryFloatingPointPropertiesBinade(_ n: Int) {
var xs = [Double]()
xs.reserveCapacity(N)
for _ in 1...N {
xs.reserveCapacity(n)
for _ in 1...n {
var x = 0 as Double
for i in 0..<10000 {
x += Double(getInt(i)).binade
}
xs.append(x)
}
CheckResults(xs[getInt(0)] == 37180757)
check(xs[getInt(0)] == 37180757)
}
@inline(never)
public func run_BinaryFloatingPointPropertiesNextUp(_ N: Int) {
public func run_BinaryFloatingPointPropertiesNextUp(_ n: Int) {
var xs = [Int]()
xs.reserveCapacity(N)
for _ in 1...N {
xs.reserveCapacity(n)
for _ in 1...n {
var x = 0 as Int
for i in 0..<10000 {
x += Int(Double(getInt(i)).nextUp)
}
xs.append(x)
}
CheckResults(xs[getInt(0)] == 49995000)
check(xs[getInt(0)] == 49995000)
}
@inline(never)
public func run_BinaryFloatingPointPropertiesUlp(_ N: Int) {
public func run_BinaryFloatingPointPropertiesUlp(_ n: Int) {
var xs = [Int]()
xs.reserveCapacity(N)
for _ in 1...N {
xs.reserveCapacity(n)
for _ in 1...n {
var x = 0 as Int
for i in 0..<10000 {
x += Int(Double(getInt(i)).ulp)
}
xs.append(x)
}
CheckResults(xs[getInt(0)] == 0)
check(xs[getInt(0)] == 0)
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -15,10 +15,11 @@
// rdar://problem/22151678
import TestsUtils
public let BitCount = BenchmarkInfo(
name: "BitCount",
runFunction: run_BitCount,
tags: [.validation, .algorithm])
public let benchmarks =
BenchmarkInfo(
name: "BitCount",
runFunction: run_BitCount,
tags: [.validation, .algorithm])
func countBitSet(_ num: Int) -> Int {
let bits = MemoryLayout<Int>.size * 8
@@ -34,13 +35,13 @@ func countBitSet(_ num: Int) -> Int {
}
@inline(never)
public func run_BitCount(_ N: Int) {
public func run_BitCount(_ n: Int) {
var sum = 0
for _ in 1...1000*N {
for _ in 1...1000*n {
// Check some results.
sum = sum &+ countBitSet(getInt(1))
&+ countBitSet(getInt(2))
&+ countBitSet(getInt(2457))
}
CheckResults(sum == 8 * 1000 * N)
check(sum == 8 * 1000 * n)
}

View File

@@ -16,7 +16,7 @@ import TestsUtils
// breadcrumbs. These are used to speed up range- and positional access through
// conventional NSString APIs.
public let Breadcrumbs: [BenchmarkInfo] = [
public let benchmarks: [BenchmarkInfo] = [
UTF16ToIdx(workload: longASCIIWorkload, count: 5_000).info,
UTF16ToIdx(workload: longMixedWorkload, count: 5_000).info,
IdxToUTF16(workload: longASCIIWorkload, count: 5_000).info,

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -27,12 +27,13 @@
import TestsUtils
public let BucketSort = BenchmarkInfo(
name: "BucketSort",
runFunction: run_BucketSort,
tags: [.validation, .algorithm],
setUpFunction: { blackHole(buckets) }
)
public let benchmarks =
BenchmarkInfo(
name: "BucketSort",
runFunction: run_BucketSort,
tags: [.validation, .algorithm],
setUpFunction: { blackHole(buckets) }
)
public protocol IntegerConvertible {
func convertToInt() -> Int
@@ -122,10 +123,10 @@ let buckets: [Bucket<Int>] = {
}()
@inline(never)
func run_BucketSort(_ N : Int) {
for _ in 0..<N {
func run_BucketSort(_ n : Int) {
for _ in 0..<n {
let sortedArray = bucketSort(
items, sortingAlgorithm: InsertionSort(), bucketArray: buckets)
CheckResults(isAscending(sortedArray))
check(isAscending(sortedArray))
}
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2020 Apple Inc. and the Swift project authors
// Copyright (c) 2020 - 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
@@ -12,7 +12,7 @@
import TestsUtils
public let BufferFill = [
public let benchmarks = [
BenchmarkInfo(name: "BufferFillFromSlice",
runFunction: bufferFillFromSliceExecute,
tags: [.validation, .api],
@@ -61,10 +61,10 @@ public func bufferFillFromSliceExecute(n: Int) {
let slice = Slice(base: a, bounds: a.indices)
var (iterator, copied) = b.initialize(from: slice)
blackHole(b)
CheckResults(copied == a.count && iterator.next() == nil)
check(copied == a.count && iterator.next() == nil)
}
CheckResults(a[r] == b[r])
check(a[r] == b[r])
}
var ra: [UInt8] = []
@@ -94,7 +94,7 @@ public func rawBufferCopyBytesExecute(n: Int) {
blackHole(rb)
}
CheckResults(ra[r] == rb[r])
check(ra[r] == rb[r])
}
public func rawBufferInitializeMemorySetup() {
@@ -117,12 +117,12 @@ public func rawBufferInitializeMemoryExecute(n: Int) {
for _ in 0..<n {
var (iterator, initialized) = rb.initializeMemory(as: Int.self, from: a)
blackHole(rb)
CheckResults(initialized.count == a.count && iterator.next() == nil)
check(initialized.count == a.count && iterator.next() == nil)
}
let offset = rb.baseAddress!.advanced(by: r*MemoryLayout<Int>.stride)
let value = offset.load(as: Int.self)
CheckResults(value == a[r])
check(value == a[r])
}
var r8: UnsafeRawBufferPointer = .init(start: nil, count: 0)
@@ -159,8 +159,8 @@ public func rawBufferCopyContentsExecute(n: Int) {
for _ in 0..<n {
var (iterator, initialized) = b8.initialize(from: r8)
blackHole(b8)
CheckResults(initialized == r8.count && iterator.next() == nil)
check(initialized == r8.count && iterator.next() == nil)
}
CheckResults(b8[r] == r8[r])
check(b8[r] == r8[r])
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -15,10 +15,11 @@
import TestsUtils
public let ByteSwap = BenchmarkInfo(
name: "ByteSwap",
runFunction: run_ByteSwap,
tags: [.validation, .algorithm])
public let benchmarks =
BenchmarkInfo(
name: "ByteSwap",
runFunction: run_ByteSwap,
tags: [.validation, .algorithm])
// a naive O(n) implementation of byteswap.
@inline(never)
@@ -44,14 +45,14 @@ func byteswap_logn(_ a: UInt64) -> UInt64 {
}
@inline(never)
public func run_ByteSwap(_ N: Int) {
public func run_ByteSwap(_ n: Int) {
var s: UInt64 = 0
for _ in 1...10000*N {
for _ in 1...10000*n {
// Check some results.
let x : UInt64 = UInt64(getInt(0))
s = s &+ byteswap_logn(byteswap_n(x &+ 2457))
&+ byteswap_logn(byteswap_n(x &+ 9129))
&+ byteswap_logn(byteswap_n(x &+ 3333))
}
CheckResults(s == (2457 &+ 9129 &+ 3333) &* 10000 &* N)
check(s == (2457 &+ 9129 &+ 3333) &* 10000 &* n)
}

View File

@@ -15,12 +15,13 @@ import TestsUtils
// This test makes sure that even though we have +0 arguments by default that we
// can properly convert +0 -> +1 to avoid extra COW copies.
public let COWArrayGuaranteedParameterOverhead = BenchmarkInfo(
name: "COWArrayGuaranteedParameterOverhead",
runFunction: run_COWArrayGuaranteedParameterOverhead,
tags: [.regression, .abstraction, .refcount],
legacyFactor: 50
)
public let benchmarks =
BenchmarkInfo(
name: "COWArrayGuaranteedParameterOverhead",
runFunction: run_COWArrayGuaranteedParameterOverhead,
tags: [.regression, .abstraction, .refcount],
legacyFactor: 50
)
@inline(never)
func caller() {
@@ -37,8 +38,8 @@ func callee(_ x: [Int]) -> [Int] {
}
@inline(never)
public func run_COWArrayGuaranteedParameterOverhead(_ N: Int) {
for _ in 0..<N*400 {
public func run_COWArrayGuaranteedParameterOverhead(_ n: Int) {
for _ in 0..<n*400 {
caller()
}
}

View File

@@ -5,20 +5,22 @@
import TestsUtils
public var COWTree = BenchmarkInfo(
name: "COWTree",
runFunction: run_COWTree,
tags: [.validation, .abstraction, .String],
legacyFactor: 20
)
public let benchmarks = [
BenchmarkInfo(
name: "COWTree",
runFunction: run_COWTree,
tags: [.validation, .abstraction, .String],
legacyFactor: 20
),
]
@inline(never)
public func run_COWTree(_ N: Int) {
public func run_COWTree(_ n: Int) {
var tree1 = Tree<String>()
var tree2 = Tree<String>()
var tree3 = Tree<String>()
for _ in 1...50*N {
for _ in 1...50*n {
tree1 = Tree<String>()
tree1.insert("Emily")
tree2 = tree1
@@ -31,7 +33,7 @@ public func run_COWTree(_ N: Int) {
}
}
CheckResults(checkRef(tree1, tree2, tree3))
check(checkRef(tree1, tree2, tree3))
}
@inline(never)

View File

@@ -1,5 +1,5 @@
import TestsUtils
public let CSVParsing = [
public let benchmarks = [
BenchmarkInfo(
name: "CSVParsing.Char",
runFunction: run_CSVParsing_characters,
@@ -346,7 +346,7 @@ public func buildWorkload() {
let altIndices: [[String]] = contents.parseAltIndices().map {
$0.map { String($0) }
}
CheckResults(alt.elementsEqual(altIndices))
check(alt.elementsEqual(altIndices))
var remainder = workload[...]
@@ -359,13 +359,13 @@ public func buildWorkload() {
res[res.endIndex-1].append(field)
}
}
CheckResults(alt.elementsEqual(parseResult))
check(alt.elementsEqual(parseResult))
}
@inline(never)
public func run_CSVParsing_characters(_ N: Int) {
public func run_CSVParsing_characters(_ n: Int) {
let contents = workload
for _ in 0..<N {
for _ in 0..<n {
var remainder = contents[...]
let result = try! parseCSV(&remainder, initialState: 0) {
(result: inout Int, _, substr) in
@@ -377,9 +377,9 @@ public func run_CSVParsing_characters(_ N: Int) {
}
@inline(never)
public func run_CSVParsing_scalars(_ N: Int) {
public func run_CSVParsing_scalars(_ n: Int) {
let contents = workload.unicodeScalars
for _ in 0..<N {
for _ in 0..<n {
var remainder = contents[...]
let result = try! parseCSV(&remainder, initialState: 0) {
(result: inout Int, _, substr) in
@@ -391,9 +391,9 @@ public func run_CSVParsing_scalars(_ N: Int) {
}
@inline(never)
public func run_CSVParsing_utf16(_ N: Int) {
public func run_CSVParsing_utf16(_ n: Int) {
let contents = workload.utf16
for _ in 0..<N {
for _ in 0..<n {
var remainder = contents[...]
let result = try! parseCSV(&remainder, initialState: 0) {
(result: inout Int, _, substr) in
@@ -405,9 +405,9 @@ public func run_CSVParsing_utf16(_ N: Int) {
}
@inline(never)
public func run_CSVParsing_utf8(_ N: Int) {
public func run_CSVParsing_utf8(_ n: Int) {
let contents = workload.utf8
for _ in 0..<N {
for _ in 0..<n {
var remainder = contents[...]
let result = try! parseCSV(&remainder, initialState: 0) {
(result: inout Int, _, substr) in
@@ -420,17 +420,17 @@ public func run_CSVParsing_utf8(_ N: Int) {
@inline(never)
public func run_CSVParsingAlt(_ N: Int) {
public func run_CSVParsingAlt(_ n: Int) {
let contents = workload
for _ in 0..<N {
for _ in 0..<n {
blackHole(contents.parseAlt())
}
}
@inline(never)
public func run_CSVParsingAltIndices(_ N: Int) {
public func run_CSVParsingAltIndices(_ n: Int) {
let contents = workload
for _ in 0..<N {
for _ in 0..<n {
blackHole(contents.parseAltIndices())
}
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -19,7 +19,7 @@ import MSVCRT
import Darwin
#endif
public let CString = [
public let benchmarks = [
BenchmarkInfo(name: "CStringLongAscii", runFunction: run_CStringLongAscii, tags: [.validation, .api, .String, .bridging]),
BenchmarkInfo(name: "CStringLongNonAscii", runFunction: run_CStringLongNonAscii, tags: [.validation, .api, .String, .bridging]),
BenchmarkInfo(name: "CStringShortAscii", runFunction: run_CStringShortAscii, tags: [.validation, .api, .String, .bridging], legacyFactor: 10),
@@ -33,30 +33,30 @@ let japanese = "日本語(にほんご、にっぽんご)は、主に日本
var repeatedStr: String! = String(repeating: "x", count: 5 * (1 << 16))
@inline(never)
public func run_StringWithCString(_ N: Int) {
public func run_StringWithCString(_ n: Int) {
let str: String = repeatedStr
for _ in 0 ..< N {
for _ in 0 ..< n {
str.withCString { blackHole($0) }
}
}
@inline(never)
public func run_CStringLongAscii(_ N: Int) {
public func run_CStringLongAscii(_ n: Int) {
var res = 0
for _ in 1...N*500 {
for _ in 1...n*500 {
// static string to c -> from c to String -> implicit conversion
res &= strlen(ascii.withCString(String.init(cString:)))
}
CheckResults(res == 0)
check(res == 0)
}
@inline(never)
public func run_CStringLongNonAscii(_ N: Int) {
public func run_CStringLongNonAscii(_ n: Int) {
var res = 0
for _ in 1...N*500 {
for _ in 1...n*500 {
res &= strlen(japanese.withCString(String.init(cString:)))
}
CheckResults(res == 0)
check(res == 0)
}
@@ -74,9 +74,9 @@ let input = ["-237392", "293715", "126809", "333779", "-362824", "144198",
let reference = 517492
@inline(never)
public func run_CStringShortAscii(_ N: Int) {
public func run_CStringShortAscii(_ n: Int) {
func DoOneIter(_ arr: [String]) -> Int {
func doOneIter(_ arr: [String]) -> Int {
var r = 0
for n in arr {
r += Int(atoi(n))
@@ -88,11 +88,11 @@ public func run_CStringShortAscii(_ N: Int) {
}
var res = Int.max
for _ in 1...10*N {
for _ in 1...10*n {
let strings = input.map {
$0.withCString(String.init(cString:))
}
res = res & DoOneIter(strings)
res = res & doOneIter(strings)
}
CheckResults(res == reference)
check(res == reference)
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -12,10 +12,11 @@
import TestsUtils
public let Calculator = BenchmarkInfo(
name: "Calculator",
runFunction: run_Calculator,
tags: [.validation])
public let benchmarks =
BenchmarkInfo(
name: "Calculator",
runFunction: run_Calculator,
tags: [.validation])
@inline(never)
func my_atoi_impl(_ input : String) -> Int {
@@ -35,9 +36,9 @@ func my_atoi_impl(_ input : String) -> Int {
}
@inline(never)
public func run_Calculator(_ N: Int) {
public func run_Calculator(_ n: Int) {
var c = 0
for _ in 1...N*800 {
for _ in 1...n*800 {
c += my_atoi_impl(identity("1"))
c += my_atoi_impl(identity("2"))
c += my_atoi_impl(identity("3"))
@@ -50,5 +51,5 @@ public func run_Calculator(_ N: Int) {
c += my_atoi_impl(identity("10"))
c -= 45
}
CheckResults(c == 0)
check(c == 0)
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -12,11 +12,12 @@
import TestsUtils
public let CaptureProp = BenchmarkInfo(
name: "CaptureProp",
runFunction: run_CaptureProp,
tags: [.validation, .api, .refcount],
legacyFactor: 10)
public let benchmarks =
BenchmarkInfo(
name: "CaptureProp",
runFunction: run_CaptureProp,
tags: [.validation, .api, .refcount],
legacyFactor: 10)
func sum(_ x:Int, y:Int) -> Int {
return x + y
@@ -32,9 +33,9 @@ func benchCaptureProp<S : Sequence
return IteratorSequence(it).reduce(initial, f)
}
public func run_CaptureProp(_ N: Int) {
public func run_CaptureProp(_ n: Int) {
let a = 1...10_000
for _ in 1...10*N {
for _ in 1...10*n {
_ = benchCaptureProp(a, sum)
}
}

View File

@@ -343,26 +343,28 @@ extension UInt32 {
}
public let ChaCha = BenchmarkInfo(
name: "ChaCha",
runFunction: run_ChaCha,
tags: [.runtime, .cpubench])
public let benchmarks = [
BenchmarkInfo(
name: "ChaCha",
runFunction: run_ChaCha,
tags: [.runtime, .cpubench]),
]
@inline(never)
func checkResult(_ plaintext: [UInt8]) {
CheckResults(plaintext.first! == 6 && plaintext.last! == 254)
check(plaintext.first! == 6 && plaintext.last! == 254)
var hash: UInt64 = 0
for byte in plaintext {
// rotate
hash = (hash &<< 8) | (hash &>> (64 - 8))
hash ^= UInt64(byte)
}
CheckResults(hash == 0xa1bcdb217d8d14e4)
check(hash == 0xa1bcdb217d8d14e4)
}
@inline(never)
@_assemblyVision
public func run_ChaCha(_ N: Int) {
public func run_ChaCha(_ n: Int) {
let key = Array(repeating: UInt8(1), count: 32)
let nonce = Array(repeating: UInt8(2), count: 12)
@@ -371,7 +373,7 @@ public func run_ChaCha(_ N: Int) {
checkResult(checkedtext)
var plaintext = Array(repeating: UInt8(0), count: 30720) // Chosen for CI runtime
for _ in 1...N {
for _ in 1...n {
ChaCha20.encrypt(bytes: &plaintext, key: key, nonce: nonce)
blackHole(plaintext.first!)
}

View File

@@ -1,6 +1,6 @@
import TestsUtils
public let ChainedFilterMap = [
public let benchmarks = [
BenchmarkInfo(name: "ChainedFilterMap", runFunction: run_ChainedFilterMap,
tags: [.algorithm], setUpFunction: { blackHole(first100k) },
legacyFactor: 9),
@@ -12,9 +12,9 @@ public let ChainedFilterMap = [
public let first100k = Array(0...100_000-1)
@inline(never)
public func run_ChainedFilterMap(_ N: Int) {
public func run_ChainedFilterMap(_ n: Int) {
var result = 0
for _ in 1...N {
for _ in 1...n {
let numbers = first100k.lazy
.filter { $0 % 3 == 0 }
.map { $0 * 2 }
@@ -23,13 +23,13 @@ public func run_ChainedFilterMap(_ N: Int) {
result = numbers.reduce(into: 0) { $0 += $1 }
}
CheckResults(result == 416691666)
check(result == 416691666)
}
@inline(never)
public func run_FatCompactMap(_ N: Int) {
public func run_FatCompactMap(_ n: Int) {
var result = 0
for _ in 1...N {
for _ in 1...n {
let numbers = first100k.lazy
.compactMap { (x: Int) -> Int? in
if x % 3 != 0 { return nil }
@@ -40,5 +40,5 @@ public func run_FatCompactMap(_ N: Int) {
}
result = numbers.reduce(into: 0) { $0 += $1 }
}
CheckResults(result == 416691666)
check(result == 416691666)
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -15,10 +15,11 @@
// and retain a StringBuffer.
import TestsUtils
public let CharacterLiteralsLarge = BenchmarkInfo(
name: "CharacterLiteralsLarge",
runFunction: run_CharacterLiteralsLarge,
tags: [.validation, .api, .String])
public let benchmarks =
BenchmarkInfo(
name: "CharacterLiteralsLarge",
runFunction: run_CharacterLiteralsLarge,
tags: [.validation, .api, .String])
@inline(never)
func makeCharacter_UTF8Length9() -> Character {
@@ -40,8 +41,8 @@ func makeCharacter_UTF8Length12() -> Character {
return "\u{00a9}\u{0300}\u{0301}\u{0302}\u{0303}\u{0304}"
}
public func run_CharacterLiteralsLarge(_ N: Int) {
for _ in 0...10000 * N {
public func run_CharacterLiteralsLarge(_ n: Int) {
for _ in 0...10000 * n {
_ = makeCharacter_UTF8Length9()
_ = makeCharacter_UTF8Length10()
_ = makeCharacter_UTF8Length11()

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -15,10 +15,11 @@
// represented as a packed integer.
import TestsUtils
public let CharacterLiteralsSmall = BenchmarkInfo(
name: "CharacterLiteralsSmall",
runFunction: run_CharacterLiteralsSmall,
tags: [.validation, .api, .String])
public let benchmarks =
BenchmarkInfo(
name: "CharacterLiteralsSmall",
runFunction: run_CharacterLiteralsSmall,
tags: [.validation, .api, .String])
@inline(never)
func makeCharacter_UTF8Length1() -> Character {
@@ -72,8 +73,8 @@ func makeLiterals() {
blackHole(makeCharacter_UTF8Length8())
}
public func run_CharacterLiteralsSmall(_ N: Int) {
for _ in 0...10000 * N {
public func run_CharacterLiteralsSmall(_ n: Int) {
for _ in 0...10000 * n {
makeLiterals()
}
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -19,33 +19,35 @@
import TestsUtils
import Foundation
public let CharacterPropertiesFetch = BenchmarkInfo(
name: "CharacterPropertiesFetch",
runFunction: run_CharacterPropertiesFetch,
tags: [.validation, .api, .String],
setUpFunction: { blackHole(workload) },
legacyFactor: 10)
public let benchmarks = [
BenchmarkInfo(
name: "CharacterPropertiesFetch",
runFunction: run_CharacterPropertiesFetch,
tags: [.validation, .api, .String],
setUpFunction: { blackHole(workload) },
legacyFactor: 10),
public let CharacterPropertiesStashed = BenchmarkInfo(
name: "CharacterPropertiesStashed",
runFunction: run_CharacterPropertiesStashed,
tags: [.validation, .api, .String],
setUpFunction: { setupStash() },
legacyFactor: 10)
BenchmarkInfo(
name: "CharacterPropertiesStashed",
runFunction: run_CharacterPropertiesStashed,
tags: [.validation, .api, .String],
setUpFunction: { setupStash() },
legacyFactor: 10),
public let CharacterPropertiesStashedMemo = BenchmarkInfo(
name: "CharacterPropertiesStashedMemo",
runFunction: run_CharacterPropertiesStashedMemo,
tags: [.validation, .api, .String],
setUpFunction: { setupMemo() },
legacyFactor: 10)
BenchmarkInfo(
name: "CharacterPropertiesStashedMemo",
runFunction: run_CharacterPropertiesStashedMemo,
tags: [.validation, .api, .String],
setUpFunction: { setupMemo() },
legacyFactor: 10),
public let CharacterPropertiesPrecomputed = BenchmarkInfo(
name: "CharacterPropertiesPrecomputed",
runFunction: run_CharacterPropertiesPrecomputed,
tags: [.validation, .api, .String],
setUpFunction: { setupPrecomputed() },
legacyFactor: 10)
BenchmarkInfo(
name: "CharacterPropertiesPrecomputed",
runFunction: run_CharacterPropertiesPrecomputed,
tags: [.validation, .api, .String],
setUpFunction: { setupPrecomputed() },
legacyFactor: 10),
]
extension Character {
var firstScalar: UnicodeScalar { return unicodeScalars.first! }
@@ -358,8 +360,8 @@ let workload = """
"""
@inline(never)
public func run_CharacterPropertiesFetch(_ N: Int) {
for _ in 1...N {
public func run_CharacterPropertiesFetch(_ n: Int) {
for _ in 1...n {
for c in workload {
blackHole(isAlphanumeric(c))
blackHole(isCapitalized(c))
@@ -376,8 +378,8 @@ public func run_CharacterPropertiesFetch(_ N: Int) {
}
@inline(never)
public func run_CharacterPropertiesStashed(_ N: Int) {
for _ in 1...N {
public func run_CharacterPropertiesStashed(_ n: Int) {
for _ in 1...n {
for c in workload {
blackHole(isAlphanumericStashed(c))
blackHole(isCapitalizedStashed(c))
@@ -394,8 +396,8 @@ public func run_CharacterPropertiesStashed(_ N: Int) {
}
@inline(never)
public func run_CharacterPropertiesStashedMemo(_ N: Int) {
for _ in 1...N {
public func run_CharacterPropertiesStashedMemo(_ n: Int) {
for _ in 1...n {
for c in workload {
blackHole(isAlphanumericStashedMemo(c))
blackHole(isCapitalizedStashedMemo(c))
@@ -412,8 +414,8 @@ public func run_CharacterPropertiesStashedMemo(_ N: Int) {
}
@inline(never)
public func run_CharacterPropertiesPrecomputed(_ N: Int) {
for _ in 1...N {
public func run_CharacterPropertiesPrecomputed(_ n: Int) {
for _ in 1...n {
for c in workload {
blackHole(isAlphanumericPrecomputed(c))
blackHole(isCapitalizedPrecomputed(c))

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -20,33 +20,35 @@
import TestsUtils
import Foundation
public let CharacterPropertiesFetch = BenchmarkInfo(
name: "CharacterPropertiesFetch",
runFunction: run_CharacterPropertiesFetch,
tags: [.validation, .api, .String],
setUpFunction: { blackHole(workload) },
legacyFactor: 10)
public let benchmarks = [
BenchmarkInfo(
name: "CharacterPropertiesFetch",
runFunction: run_CharacterPropertiesFetch,
tags: [.validation, .api, .String],
setUpFunction: { blackHole(workload) },
legacyFactor: 10),
public let CharacterPropertiesStashed = BenchmarkInfo(
name: "CharacterPropertiesStashed",
runFunction: run_CharacterPropertiesStashed,
tags: [.validation, .api, .String],
setUpFunction: { setupStash() },
legacyFactor: 10)
BenchmarkInfo(
name: "CharacterPropertiesStashed",
runFunction: run_CharacterPropertiesStashed,
tags: [.validation, .api, .String],
setUpFunction: { setupStash() },
legacyFactor: 10),
public let CharacterPropertiesStashedMemo = BenchmarkInfo(
name: "CharacterPropertiesStashedMemo",
runFunction: run_CharacterPropertiesStashedMemo,
tags: [.validation, .api, .String],
setUpFunction: { setupMemo() },
legacyFactor: 10)
BenchmarkInfo(
name: "CharacterPropertiesStashedMemo",
runFunction: run_CharacterPropertiesStashedMemo,
tags: [.validation, .api, .String],
setUpFunction: { setupMemo() },
legacyFactor: 10),
public let CharacterPropertiesPrecomputed = BenchmarkInfo(
name: "CharacterPropertiesPrecomputed",
runFunction: run_CharacterPropertiesPrecomputed,
tags: [.validation, .api, .String],
setUpFunction: { setupPrecomputed() },
legacyFactor: 10)
BenchmarkInfo(
name: "CharacterPropertiesPrecomputed",
runFunction: run_CharacterPropertiesPrecomputed,
tags: [.validation, .api, .String],
setUpFunction: { setupPrecomputed() },
legacyFactor: 10),
]
extension Character {
var firstScalar: UnicodeScalar { return unicodeScalars.first! }
@@ -168,8 +170,8 @@ let workload = """
"""
@inline(never)
public func run_CharacterPropertiesFetch(_ N: Int) {
for _ in 1...N {
public func run_CharacterPropertiesFetch(_ n: Int) {
for _ in 1...n {
for c in workload {
% for Property, Set in Properties:
blackHole(is${Property}(c))
@@ -179,8 +181,8 @@ public func run_CharacterPropertiesFetch(_ N: Int) {
}
@inline(never)
public func run_CharacterPropertiesStashed(_ N: Int) {
for _ in 1...N {
public func run_CharacterPropertiesStashed(_ n: Int) {
for _ in 1...n {
for c in workload {
% for Property, Set in Properties:
blackHole(is${Property}Stashed(c))
@@ -190,8 +192,8 @@ public func run_CharacterPropertiesStashed(_ N: Int) {
}
@inline(never)
public func run_CharacterPropertiesStashedMemo(_ N: Int) {
for _ in 1...N {
public func run_CharacterPropertiesStashedMemo(_ n: Int) {
for _ in 1...n {
for c in workload {
% for Property, Set in Properties:
blackHole(is${Property}StashedMemo(c))
@@ -201,8 +203,8 @@ public func run_CharacterPropertiesStashedMemo(_ N: Int) {
}
@inline(never)
public func run_CharacterPropertiesPrecomputed(_ N: Int) {
for _ in 1...N {
public func run_CharacterPropertiesPrecomputed(_ n: Int) {
for _ in 1...n {
for c in workload {
% for Property, Set in Properties:
blackHole(is${Property}Precomputed(c))

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -13,12 +13,13 @@
// This test tests the performance of ASCII Character comparison.
import TestsUtils
public let Chars = BenchmarkInfo(
name: "Chars2",
runFunction: run_Chars,
tags: [.validation, .api, .String],
setUpFunction: { blackHole(alphabetInput) },
legacyFactor: 50)
public let benchmarks =
BenchmarkInfo(
name: "Chars2",
runFunction: run_Chars,
tags: [.validation, .api, .String],
setUpFunction: { blackHole(alphabetInput) },
legacyFactor: 50)
let alphabetInput: [Character] = [
"A", "B", "C", "D", "E", "F", "G",
@@ -30,11 +31,11 @@ let alphabetInput: [Character] = [
]
@inline(never)
public func run_Chars(_ N: Int) {
public func run_Chars(_ n: Int) {
// Permute some characters.
let alphabet: [Character] = alphabetInput
for _ in 0..<N {
for _ in 0..<n {
for firstChar in alphabet {
for lastChar in alphabet {
blackHole(firstChar < lastChar)

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -12,13 +12,14 @@
import TestsUtils
public let ClassArrayGetter = BenchmarkInfo(
name: "ClassArrayGetter2",
runFunction: run_ClassArrayGetter,
tags: [.validation, .api, .Array],
setUpFunction: { blackHole(inputArray) },
tearDownFunction: { inputArray = nil },
legacyFactor: 10)
public let benchmarks =
BenchmarkInfo(
name: "ClassArrayGetter2",
runFunction: run_ClassArrayGetter,
tags: [.validation, .api, .Array],
setUpFunction: { blackHole(inputArray) },
tearDownFunction: { inputArray = nil },
legacyFactor: 10)
class Box {
var v: Int
@@ -44,9 +45,9 @@ var inputArray: [Box]! = {
return a
}()
public func run_ClassArrayGetter(_ N: Int) {
public func run_ClassArrayGetter(_ n: Int) {
let a: [Box] = inputArray
for _ in 1...N {
for _ in 1...n {
_ = sumArray(a)
}
}

View File

@@ -1,4 +1,4 @@
//===--- JSON.swift -------------------------------------------------------===//
//===--- CodableTest.swift ------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
@@ -14,14 +14,14 @@ import TestsUtils
import Foundation
#if _runtime(_ObjC)
public let Codable = [
public let benchmarks = [
BenchmarkInfo(name: "JSONPerfEncode", runFunction: run_JSONPerfEncode, tags: [.validation, .bridging], setUpFunction: setup_json),
BenchmarkInfo(name: "JSONPerfDecode", runFunction: run_JSONPerfDecode, tags: [.validation, .bridging], setUpFunction: setup_json),
BenchmarkInfo(name: "PlistPerfEncode", runFunction: run_PlistPerfEncode, tags: [.validation, .bridging], setUpFunction: setup_plist),
BenchmarkInfo(name: "PlistPerfDecode", runFunction: run_PlistPerfDecode, tags: [.validation, .bridging], setUpFunction: setup_plist),
]
#else
public let Codable = [
public let benchmarks = [
BenchmarkInfo(name: "JSONPerfEncode", runFunction: run_JSONPerfEncode, tags: [.validation, .bridging], setUpFunction: setup_json),
BenchmarkInfo(name: "JSONPerfDecode", runFunction: run_JSONPerfDecode, tags: [.validation, .bridging], setUpFunction: setup_json),
]
@@ -101,26 +101,26 @@ struct CodablePerfTester<Enc: GenericEncoder, Dec: GenericDecoder> {
}
}
var JSONTester: CodablePerfTester<JSONEncoder, JSONDecoder>! = nil
var jsonTester: CodablePerfTester<JSONEncoder, JSONDecoder>! = nil
public func setup_json() {
JSONTester = CodablePerfTester(encoder: JSONEncoder(), decoder: JSONDecoder())
jsonTester = CodablePerfTester(encoder: JSONEncoder(), decoder: JSONDecoder())
}
@inline(never)
public func run_JSONPerfEncode(_ N: Int) {
public func run_JSONPerfEncode(_ n: Int) {
autoreleasepool {
for _ in 0 ..< N {
JSONTester.encode()
for _ in 0 ..< n {
jsonTester.encode()
}
}
}
@inline(never)
public func run_JSONPerfDecode(_ N: Int) {
public func run_JSONPerfDecode(_ n: Int) {
autoreleasepool {
for _ in 0 ..< N {
JSONTester.decode()
for _ in 0 ..< n {
jsonTester.decode()
}
}
}
@@ -134,18 +134,18 @@ public func setup_plist() {
}
@inline(never)
public func run_PlistPerfEncode(_ N: Int) {
public func run_PlistPerfEncode(_ n: Int) {
autoreleasepool {
for _ in 0 ..< N {
for _ in 0 ..< n {
plistTester.encode()
}
}
}
@inline(never)
public func run_PlistPerfDecode(_ N: Int) {
public func run_PlistPerfDecode(_ n: Int) {
autoreleasepool {
for _ in 0 ..< N {
for _ in 0 ..< n {
plistTester.decode()
}
}

View File

@@ -5,19 +5,20 @@
import TestsUtils
public var Combos = BenchmarkInfo(
name: "Combos",
runFunction: run_Combos,
tags: [.validation, .abstraction]
)
public let benchmarks =
BenchmarkInfo(
name: "Combos",
runFunction: run_Combos,
tags: [.validation, .abstraction]
)
@inline(never)
public func run_Combos(_ N: Int) {
public func run_Combos(_ n: Int) {
let firstRef = [Character("A"), Character("0")]
let lastRef = [Character("J"), Character("9")]
var combos = [[Character]]()
for _ in 1...10*N {
for _ in 1...10*n {
combos = combinations("ABCDEFGHIJ", "0123456789").map {
return [$0] + [$1]
}
@@ -27,7 +28,7 @@ public func run_Combos(_ N: Int) {
}
}
CheckResults(combos.first! == firstRef && combos.last! == lastRef)
check(combos.first! == firstRef && combos.last! == lastRef)
}
func combinations

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -15,7 +15,7 @@ import Foundation
let d: [BenchmarkCategory] = [.validation, .api, .Data, .cpubench]
public let DataBenchmarks = [
public let benchmarks = [
BenchmarkInfo(name: "DataCreateEmpty",
runFunction: { for _ in 0..<$0*10_000 { blackHole(Data()) } },
tags: d, legacyFactor: 10),
@@ -394,8 +394,8 @@ func sampleData(_ type: SampleKind) -> Data {
}
@inline(never)
func withUnsafeBytes(_ N: Int, data: Data) {
for _ in 1...N {
func withUnsafeBytes(_ n: Int, data: Data) {
for _ in 1...n {
data.withUnsafeBytes { (ptr: UnsafePointer<UInt8>) in
blackHole(ptr.pointee)
}
@@ -403,8 +403,8 @@ func withUnsafeBytes(_ N: Int, data: Data) {
}
@inline(never)
func withUnsafeMutableBytes(_ N: Int, data: Data) {
for _ in 1...N {
func withUnsafeMutableBytes(_ n: Int, data: Data) {
for _ in 1...n {
var copy = data
copy.withUnsafeMutableBytes { (ptr: UnsafeMutablePointer<UInt8>) in
// Mutate a byte
@@ -414,61 +414,61 @@ func withUnsafeMutableBytes(_ N: Int, data: Data) {
}
@inline(never)
func copyBytes(_ N: Int, data: Data) {
func copyBytes(_ n: Int, data: Data) {
let amount = data.count
let buffer = UnsafeMutablePointer<UInt8>.allocate(capacity: amount)
defer { buffer.deallocate() }
for _ in 1...N {
for _ in 1...n {
data.copyBytes(to: buffer, from: 0..<amount)
}
}
@inline(never)
func append(_ N: Int, bytes count: Int, to data: Data) {
func append(_ n: Int, bytes count: Int, to data: Data) {
let bytes = malloc(count).assumingMemoryBound(to: UInt8.self)
defer { free(bytes) }
for _ in 1...N {
for _ in 1...n {
var copy = data
copy.append(bytes, count: count)
}
}
@inline(never)
func append(_ N: Int, array bytes: [UInt8], to data: Data) {
for _ in 1...N {
func append(_ n: Int, array bytes: [UInt8], to data: Data) {
for _ in 1...n {
var copy = data
copy.append(contentsOf: bytes)
}
}
@inline(never)
func append(_ N: Int, sequenceLength: Int, to data: Data) {
func append(_ n: Int, sequenceLength: Int, to data: Data) {
let bytes = repeatElement(UInt8(0xA0), count: sequenceLength)
for _ in 1...N {
for _ in 1...n {
var copy = data
copy.append(contentsOf: bytes)
}
}
@inline(never)
func append<S: Sequence>(_ N: Int, sequence: S, to data: Data)
func append<S: Sequence>(_ n: Int, sequence: S, to data: Data)
where S.Element == UInt8 {
for _ in 1...N {
for _ in 1...n {
var copy = data
copy.append(contentsOf: sequence)
}
}
@inline(never)
func _init<S: Sequence>(_ N: Int, sequence: S) where S.Element == UInt8 {
for _ in 1...N {
func _init<S: Sequence>(_ n: Int, sequence: S) where S.Element == UInt8 {
for _ in 1...n {
blackHole(Data(sequence))
}
}
@inline(never)
func resetBytes(_ N: Int, in range: Range<Data.Index>, data: Data) {
for _ in 1...N {
func resetBytes(_ n: Int, in range: Range<Data.Index>, data: Data) {
for _ in 1...n {
var copy = data
copy.resetBytes(in: range)
}
@@ -476,12 +476,12 @@ func resetBytes(_ N: Int, in range: Range<Data.Index>, data: Data) {
@inline(never)
func replace(
_ N: Int,
_ n: Int,
data: Data,
subrange range: Range<Data.Index>,
with replacement: Data
) {
for _ in 1...N {
for _ in 1...n {
var copy = data
copy.replaceSubrange(range, with: replacement)
}
@@ -489,7 +489,7 @@ func replace(
@inline(never)
func replaceBuffer(
_ N: Int,
_ n: Int,
data: Data,
subrange range: Range<Data.Index>,
with replacement: Data
@@ -497,7 +497,7 @@ func replaceBuffer(
replacement.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) in
let buffer = UnsafeBufferPointer(start: bytes, count: replacement.count)
for _ in 1...N {
for _ in 1...n {
var copy = data
copy.replaceSubrange(range, with: buffer)
}
@@ -505,57 +505,57 @@ func replaceBuffer(
}
@inline(never)
func append(_ N: Int, data: Data, to target: Data) {
func append(_ n: Int, data: Data, to target: Data) {
var copy: Data
for _ in 1...N {
for _ in 1...n {
copy = target
copy.append(data)
}
}
@inline(never)
public func count(_ N: Int, data: Data) {
for _ in 1...N {
public func count(_ n: Int, data: Data) {
for _ in 1...n {
blackHole(data.count)
}
}
@inline(never)
public func setCount(_ N: Int, data: Data, extra: Int) {
public func setCount(_ n: Int, data: Data, extra: Int) {
var copy = data
let count = data.count + extra
let orig = data.count
for _ in 1...N {
for _ in 1...n {
copy.count = count
copy.count = orig
}
}
@inline(never)
public func string(_ N: Int, from data: Data) {
for _ in 1...N {
public func string(_ n: Int, from data: Data) {
for _ in 1...n {
blackHole(String(decoding: data, as: UTF8.self))
}
}
@inline(never)
public func dataFromUTF8View(_ N: Int, from string: String) {
for _ in 1...N {
public func dataFromUTF8View(_ n: Int, from string: String) {
for _ in 1...n {
blackHole(Data(string.utf8))
}
}
@inline(never)
public func dataUsingUTF8Encoding(_ N: Int, from string: String) {
for _ in 1...N {
public func dataUsingUTF8Encoding(_ n: Int, from string: String) {
for _ in 1...n {
autoreleasepool { blackHole(string.data(using: .utf8)) }
}
}
@inline(never)
public func hash(_ N: Int, data: Data) {
public func hash(_ n: Int, data: Data) {
var hasher = Hasher()
for _ in 0 ..< N {
for _ in 0 ..< n {
hasher.combine(data)
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -13,20 +13,21 @@
// rdar://problem/20980377
import TestsUtils
public let DeadArray = BenchmarkInfo(
name: "DeadArray",
runFunction: run_DeadArray,
tags: [.regression, .unstable],
legacyFactor: 200
)
public let benchmarks =
BenchmarkInfo(
name: "DeadArray",
runFunction: run_DeadArray,
tags: [.regression, .unstable],
legacyFactor: 200
)
@inline(__always)
func debug(_ m:String) {}
private var Count = 0
private var count = 0
@inline(never)
func bar() { Count += 1 }
func bar() { count += 1 }
@inline(never)
func runLoop(_ var1: Int, var2: Int) {
@@ -37,10 +38,10 @@ func runLoop(_ var1: Int, var2: Int) {
}
@inline(never)
public func run_DeadArray(_ N: Int) {
for _ in 1...N {
Count = 0
public func run_DeadArray(_ n: Int) {
for _ in 1...n {
count = 0
runLoop(0, var2: 0)
}
CheckResults(Count == 500)
check(count == 500)
}

View File

@@ -12,7 +12,7 @@
import TestsUtils
public let DevirtualizeProtocolComposition = [
public let benchmarks = [
BenchmarkInfo(name: "DevirtualizeProtocolComposition", runFunction: run_DevirtualizeProtocolComposition, tags: [.validation, .api]),
]
@@ -38,8 +38,8 @@ func playGame<T>(_ x: Game<T> & Pingable) -> Int {
}
@inline(never)
public func run_DevirtualizeProtocolComposition(N: Int) {
for _ in 0..<N * 20_000 {
public func run_DevirtualizeProtocolComposition(n: Int) {
for _ in 0..<n * 20_000 {
blackHole(playGame(PingPong()))
}
}

View File

@@ -6,14 +6,16 @@
import TestsUtils
public var DictOfArraysToArrayOfDicts = BenchmarkInfo(
name: "DictOfArraysToArrayOfDicts",
runFunction: run_DictOfArraysToArrayOfDicts,
tags: [.algorithm, .Dictionary]
)
public let benchmarks = [
BenchmarkInfo(
name: "DictOfArraysToArrayOfDicts",
runFunction: run_DictOfArraysToArrayOfDicts,
tags: [.algorithm, .Dictionary]
),
]
@inline(never)
public func run_DictOfArraysToArrayOfDicts(_ N: Int) {
public func run_DictOfArraysToArrayOfDicts(_ n: Int) {
let returnedFromServer = [
"title": ["abc", "def", "ghi"],
"time": ["1234", "5678", "0123"],
@@ -23,7 +25,7 @@ public func run_DictOfArraysToArrayOfDicts(_ N: Int) {
var inverted: [[(String, String)]] = []
var arrayOfDicts: [[String: String]] = [[:]]
for _ in 1...100*N {
for _ in 1...100*n {
pairs = returnedFromServer.map {
(key, value) in value.map { (key, $0) }
}
@@ -39,7 +41,7 @@ public func run_DictOfArraysToArrayOfDicts(_ N: Int) {
}
}
CheckResults(arrayOfDicts.count == 3)
check(arrayOfDicts.count == 3)
}
// Given [

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -13,7 +13,7 @@
import TestsUtils
public let Dictionary = [
public let benchmarks = [
BenchmarkInfo(name: "Dictionary", runFunction: run_Dictionary,
tags: [.validation, .api, .Dictionary],
setUpFunction: { blackHole(half) },
@@ -134,30 +134,30 @@ let half: Dictionary<String, Bool> = {
}()
@inline(never)
public func run_Dictionary(N: Int) {
public func run_Dictionary(n: Int) {
var dict: Dictionary<String, Bool> = [:]
// Check performance of filling the dictionary:
for _ in 1...N {
for _ in 1...n {
dict = [:]
for word in text {
dict[word] = true
}
}
CheckResults(dict.count == 270)
check(dict.count == 270)
// Check performance of searching in the dictionary:
dict = half
// Count number of words from the first half in the entire text
var count = 0
for _ in 1...N {
for _ in 1...n {
for word in text {
if dict[word] != nil {
count += 1
}
}
}
CheckResults(count == N*541)
check(count == n*541)
}
class Box<T : Hashable> : Hashable {
@@ -187,28 +187,28 @@ let halfObjects: Dictionary<Box<String>, Box<Bool>> = {
}()
@inline(never)
public func run_DictionaryOfObjects(N: Int) {
public func run_DictionaryOfObjects(n: Int) {
var dict: Dictionary<Box<String>, Box<Bool>> = [:]
// Check performance of filling the dictionary:
for _ in 1...N {
for _ in 1...n {
dict = [:]
for word in text {
dict[Box(word)] = Box(true)
}
}
CheckResults(dict.count == 270)
check(dict.count == 270)
// Check performance of searching in the dictionary:
dict = halfObjects
// Count number of words from the first half in the entire text
var count = 0
for _ in 1...N {
for _ in 1...n {
for word in text {
if dict[Box(word)] != nil {
count += 1
}
}
}
CheckResults(count == N*541)
check(count == n*541)
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -12,7 +12,7 @@
import TestsUtils
public let Dictionary2 = [
public let benchmarks = [
BenchmarkInfo(name: "Dictionary2",
runFunction: run_Dictionary2,
tags: [.validation, .api, .Dictionary],
@@ -24,11 +24,11 @@ public let Dictionary2 = [
]
@inline(never)
public func run_Dictionary2(_ N: Int) {
public func run_Dictionary2(_ n: Int) {
let size = 500
let ref_result = 199
var res = 0
for _ in 1...N {
for _ in 1...n {
var x: [String: Int] = [:]
for i in 1...size {
x[String(i, radix:16)] = i
@@ -45,7 +45,7 @@ public func run_Dictionary2(_ N: Int) {
break
}
}
CheckResults(res == ref_result)
check(res == ref_result)
}
class Box<T : Hashable> : Hashable {
@@ -65,12 +65,12 @@ class Box<T : Hashable> : Hashable {
}
@inline(never)
public func run_Dictionary2OfObjects(_ N: Int) {
public func run_Dictionary2OfObjects(_ n: Int) {
let size = 500
let ref_result = 199
var res = 0
for _ in 1...N {
for _ in 1...n {
var x: [Box<String>:Box<Int>] = [:]
for i in 1...size {
x[Box(String(i, radix:16))] = Box(i)
@@ -87,5 +87,5 @@ public func run_Dictionary2OfObjects(_ N: Int) {
break
}
}
CheckResults(res == ref_result)
check(res == ref_result)
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -12,13 +12,13 @@
import TestsUtils
public let Dictionary3 = [
public let benchmarks = [
BenchmarkInfo(name: "Dictionary3", runFunction: run_Dictionary3, tags: [.validation, .api, .Dictionary]),
BenchmarkInfo(name: "Dictionary3OfObjects", runFunction: run_Dictionary3OfObjects, tags: [.validation, .api, .Dictionary]),
]
@inline(never)
public func run_Dictionary3(_ N: Int) {
public func run_Dictionary3(_ n: Int) {
let size1 = 100
let reps = 20
let ref_result = "1 99 20 1980"
@@ -26,7 +26,7 @@ public func run_Dictionary3(_ N: Int) {
var hash2 = [String: Int]()
var res = ""
for _ in 1...N {
for _ in 1...n {
hash1 = [:]
for i in 0..<size1 {
hash1["foo_" + String(i)] = i
@@ -46,7 +46,7 @@ public func run_Dictionary3(_ N: Int) {
break
}
}
CheckResults(res == ref_result)
check(res == ref_result)
}
class Box<T : Hashable> : Hashable {
@@ -66,7 +66,7 @@ class Box<T : Hashable> : Hashable {
}
@inline(never)
public func run_Dictionary3OfObjects(_ N: Int) {
public func run_Dictionary3OfObjects(_ n: Int) {
let size1 = 100
let reps = 20
let ref_result = "1 99 20 1980"
@@ -74,7 +74,7 @@ public func run_Dictionary3OfObjects(_ N: Int) {
var hash2 : [ Box<String> : Box<Int> ] = [:]
var res = ""
for _ in 1...N {
for _ in 1...n {
hash1 = [:]
for i in 0..<size1 {
hash1[Box("foo_" + String(i))] = Box(i)
@@ -94,5 +94,5 @@ public func run_Dictionary3OfObjects(_ N: Int) {
break
}
}
CheckResults(res == ref_result)
check(res == ref_result)
}

View File

@@ -15,7 +15,7 @@ import TestsUtils
// This benchmark mostly measures lookups in dictionaries with complex keys,
// exercising the default hash compression function.
public let Dictionary4 = [
public let benchmarks = [
BenchmarkInfo(
name: "Dictionary4",
runFunction: run_Dictionary4,
@@ -51,7 +51,7 @@ struct LargeKey: Hashable {
}
@inline(never)
public func run_Dictionary4(_ N: Int) {
public func run_Dictionary4(_ n: Int) {
let size1 = 100
let reps = 20
let ref_result = "1 99 \(reps) \(reps * 99)"
@@ -59,7 +59,7 @@ public func run_Dictionary4(_ N: Int) {
var hash2 = [LargeKey: Int]()
var res = ""
for _ in 1...N {
for _ in 1...n {
// Test insertions
hash1 = [:]
for i in 0..<size1 {
@@ -81,7 +81,7 @@ public func run_Dictionary4(_ N: Int) {
break
}
}
CheckResults(res == ref_result)
check(res == ref_result)
}
class Box<T : Hashable> : Hashable {
@@ -101,7 +101,7 @@ class Box<T : Hashable> : Hashable {
}
@inline(never)
public func run_Dictionary4OfObjects(_ N: Int) {
public func run_Dictionary4OfObjects(_ n: Int) {
let size1 = 100
let reps = 20
let ref_result = "1 99 \(reps) \(reps * 99)"
@@ -109,7 +109,7 @@ public func run_Dictionary4OfObjects(_ N: Int) {
var hash2 = [Box<LargeKey>: Int]()
var res = ""
for _ in 1...N {
for _ in 1...n {
// Test insertions
hash1 = [:]
for i in 0..<size1 {
@@ -131,5 +131,5 @@ public func run_Dictionary4OfObjects(_ N: Int) {
break
}
}
CheckResults(res == ref_result)
check(res == ref_result)
}

View File

@@ -15,7 +15,7 @@ import TestsUtils
// This benchmark mostly measures lookups in dictionaries with complex keys,
// using the legacy hashValue API.
public let Dictionary4Legacy = [
public let benchmarks = [
BenchmarkInfo(
name: "Dictionary4Legacy",
runFunction: run_Dictionary4Legacy,
@@ -74,7 +74,7 @@ struct LargeKey: Hashable {
}
@inline(never)
public func run_Dictionary4Legacy(_ N: Int) {
public func run_Dictionary4Legacy(_ n: Int) {
let size1 = 100
let reps = 20
let ref_result = "1 99 \(reps) \(reps * 99)"
@@ -82,7 +82,7 @@ public func run_Dictionary4Legacy(_ N: Int) {
var hash2 = [LargeKey: Int]()
var res = ""
for _ in 1...N {
for _ in 1...n {
// Test insertions
hash1 = [:]
for i in 0..<size1 {
@@ -104,7 +104,7 @@ public func run_Dictionary4Legacy(_ N: Int) {
break
}
}
CheckResults(res == ref_result)
check(res == ref_result)
}
class Box<T : Hashable> : Hashable {
@@ -128,7 +128,7 @@ class Box<T : Hashable> : Hashable {
}
@inline(never)
public func run_Dictionary4OfObjectsLegacy(_ N: Int) {
public func run_Dictionary4OfObjectsLegacy(_ n: Int) {
let size1 = 100
let reps = 20
let ref_result = "1 99 \(reps) \(reps * 99)"
@@ -136,7 +136,7 @@ public func run_Dictionary4OfObjectsLegacy(_ N: Int) {
var hash2 = [Box<LargeKey>: Int]()
var res = ""
for _ in 1...N {
for _ in 1...n {
// Test insertions
hash1 = [:]
for i in 0..<size1 {
@@ -158,5 +158,5 @@ public func run_Dictionary4OfObjectsLegacy(_ N: Int) {
break
}
}
CheckResults(res == ref_result)
check(res == ref_result)
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -16,17 +16,18 @@
import Foundation
import TestsUtils
public let DictionaryBridge = BenchmarkInfo(
name: "DictionaryBridge",
runFunction: run_DictionaryBridge,
tags: [.validation, .api, .Dictionary, .bridging])
public let benchmarks =
BenchmarkInfo(
name: "DictionaryBridge",
runFunction: run_DictionaryBridge,
tags: [.validation, .api, .Dictionary, .bridging])
#if _runtime(_ObjC)
class Thing : NSObject {
required override init() {
let c = type(of: self).col()
CheckResults(c!.count == 10)
check(c!.count == 10)
}
private class func col() -> [String : AnyObject]? {
@@ -59,9 +60,9 @@ class Stuff {
#endif
@inline(never)
public func run_DictionaryBridge(_ N: Int) {
public func run_DictionaryBridge(_ n: Int) {
#if _runtime(_ObjC)
for _ in 1...100*N {
for _ in 1...100*n {
autoreleasepool {
_ = Stuff()
}

View File

@@ -16,7 +16,7 @@ import TestsUtils
#if _runtime(_ObjC)
import Foundation
public let DictionaryBridgeToObjC = [
public let benchmarks = [
BenchmarkInfo(
name: "DictionaryBridgeToObjC_Bridge",
runFunction: run_DictionaryBridgeToObjC_BridgeToObjC,
@@ -55,32 +55,32 @@ let numbers: [String: Int] = [
]
@inline(never)
public func run_DictionaryBridgeToObjC_BridgeToObjC(_ N: Int) {
for _ in 1 ... 100 * N {
public func run_DictionaryBridgeToObjC_BridgeToObjC(_ n: Int) {
for _ in 1 ... 100 * n {
blackHole(numbers as NSDictionary)
}
}
@inline(never)
public func run_DictionaryBridgeToObjC_Access(_ N: Int) {
public func run_DictionaryBridgeToObjC_Access(_ n: Int) {
let d = numbers as NSDictionary
blackHole(d.object(forKey: "one")) // Force bridging of contents
for _ in 1 ... 100 * N {
for _ in 1 ... 100 * n {
for key in numbers.keys {
CheckResults(identity(d).object(forKey: key) != nil)
check(identity(d).object(forKey: key) != nil)
}
}
}
@inline(never)
public func run_DictionaryBridgeToObjC_BulkAccess(_ N: Int) {
public func run_DictionaryBridgeToObjC_BulkAccess(_ n: Int) {
let d = numbers as NSDictionary
for _ in 1 ... 100 * N {
for _ in 1 ... 100 * n {
let d2 = NSDictionary(dictionary: identity(d))
CheckResults(d2.count == d.count)
check(d2.count == d.count)
}
}
#else // !_runtime(ObjC)
public let DictionaryBridgeToObjC: [BenchmarkInfo] = []
public let benchmarks: [BenchmarkInfo] = []
#endif

View File

@@ -23,7 +23,7 @@ let oddStringMap: [Int: String] = Dictionary(uniqueKeysWithValues:
let t: [BenchmarkCategory] = [.validation, .api, .Dictionary]
public let DictionaryCompactMapValues = [
public let benchmarks = [
BenchmarkInfo(name: "DictionaryCompactMapValuesOfNilValue",
runFunction: compactMapValues, tags: t,
setUpFunction: { blackHole(smallOddNumMap); blackHole(compactOddNums)},
@@ -34,14 +34,14 @@ public let DictionaryCompactMapValues = [
legacyFactor: 54),
]
func compactMapValues(N: Int) {
for _ in 1...20*N {
CheckResults(smallOddNumMap.compactMapValues({$0}) == compactOddNums)
func compactMapValues(n: Int) {
for _ in 1...20*n {
check(smallOddNumMap.compactMapValues({$0}) == compactOddNums)
}
}
func compactMapValuesInt(N: Int) {
for _ in 1...20*N {
CheckResults(oddStringMap.compactMapValues(Int.init) == compactOddNums)
func compactMapValuesInt(n: Int) {
for _ in 1...20*n {
check(oddStringMap.compactMapValues(Int.init) == compactOddNums)
}
}

View File

@@ -22,7 +22,7 @@ let t: [BenchmarkCategory] = [.validation, .api, .Dictionary]
// 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.
public let DictionaryCopy = [
public let benchmarks = [
BenchmarkInfo(name:"Dict.CopyKeyValue.16k",
runFunction: copyKeyValue, tags: t, setUpFunction: { dict(16_000) }),
BenchmarkInfo(name:"Dict.CopyKeyValue.20k",
@@ -49,22 +49,22 @@ func dict(_ size: Int) {
}
@inline(never)
func copyKeyValue(N: Int) {
for _ in 1...N {
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)
check(copy.count == dict!.count)
}
}
// Filter with a predicate returning true is essentially the same loop as the
// one in copyKeyValue above.
@inline(never)
func filterAllMatch(N: Int) {
for _ in 1...N {
func filterAllMatch(n: Int) {
for _ in 1...n {
let copy = dict!.filter { _ in true }
CheckResults(copy.count == dict!.count)
check(copy.count == dict!.count)
}
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -12,7 +12,7 @@
import TestsUtils
public let DictionaryGroup = [
public let benchmarks = [
BenchmarkInfo(name: "DictionaryGroup",
runFunction: run_DictionaryGroup,
tags: [.validation, .api, .Dictionary]),
@@ -26,11 +26,11 @@ public let DictionaryGroup = [
]
@inline(never)
public func run_DictionaryGroup(_ N: Int) {
for _ in 1...N {
public func run_DictionaryGroup(_ n: Int) {
for _ in 1...n {
let dict = Dictionary(grouping: 0..<10_000, by: { $0 % 10 })
CheckResults(dict.count == 10)
CheckResults(dict[0]!.count == 1_000)
check(dict.count == 10)
check(dict[0]!.count == 1_000)
}
}
@@ -53,11 +53,11 @@ class Box<T : Hashable> : Hashable {
var inputObjects: [Box<Int>]! = (0..<1_000).lazy.map { Box($0) }
@inline(never)
public func run_DictionaryGroupOfObjects(_ N: Int) {
public func run_DictionaryGroupOfObjects(_ n: Int) {
let objects: [Box<Int>] = inputObjects
for _ in 1...N {
for _ in 1...n {
let dict = Dictionary(grouping: objects, by: { Box($0.value % 10) })
CheckResults(dict.count == 10)
CheckResults(dict[Box(0)]!.count == 100)
check(dict.count == 10)
check(dict[Box(0)]!.count == 100)
}
}

View File

@@ -16,7 +16,7 @@ import TestsUtils
import Foundation
#if _runtime(_ObjC)
public let DictionaryKeysContains = [
public let benchmarks = [
BenchmarkInfo(
name: "DictionaryKeysContainsNative",
runFunction: run_DictionaryKeysContains,
@@ -32,7 +32,7 @@ public let DictionaryKeysContains = [
tearDownFunction: teardownDictionary),
]
#else
public let DictionaryKeysContains = [
public let benchmarks = [
BenchmarkInfo(
name: "DictionaryKeysContainsNative",
runFunction: run_DictionaryKeysContains,
@@ -69,13 +69,13 @@ private func teardownDictionary() {
}
@inline(never)
public func run_DictionaryKeysContains(_ N: Int) {
public func run_DictionaryKeysContains(_ n: Int) {
#if os(Linux)
fatalError("Unsupported benchmark")
#else
for _ in 0..<(N * 100) {
CheckResults(dictionary.keys.contains("42"))
CheckResults(!dictionary.keys.contains("-1"))
for _ in 0..<(n * 100) {
check(dictionary.keys.contains("42"))
check(!dictionary.keys.contains("-1"))
}
#endif
}

View File

@@ -1,8 +1,8 @@
//===--- DictionaryLiteral.swift ------------------------------------------===//
//===--- DictionaryLiteralTest.swift --------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -14,11 +14,13 @@
// rdar://problem/19804127
import TestsUtils
public let DictionaryLiteral = BenchmarkInfo(
name: "DictionaryLiteral",
runFunction: run_DictionaryLiteral,
tags: [.validation, .api, .Dictionary],
legacyFactor: 10)
public let benchmarks = [
BenchmarkInfo(
name: "DictionaryLiteral",
runFunction: run_DictionaryLiteral,
tags: [.validation, .api, .Dictionary],
legacyFactor: 10),
]
@inline(never)
func makeDictionary() -> [Int: Int] {
@@ -26,8 +28,8 @@ func makeDictionary() -> [Int: Int] {
}
@inline(never)
public func run_DictionaryLiteral(_ N: Int) {
for _ in 1...1000*N {
public func run_DictionaryLiteral(_ n: Int) {
for _ in 1...1000*n {
_ = makeDictionary()
}
}

View File

@@ -16,7 +16,7 @@ import TestsUtils
// small ASCII String keys. Untyped NSDictionary values get imported as this
// type, so it occurs relatively often in practice.
public var DictionaryOfAnyHashableStrings = [
public let benchmarks = [
BenchmarkInfo(
name: "DictionaryOfAnyHashableStrings_insert",
runFunction: run_DictionaryOfAnyHashableStrings_insert,
@@ -74,7 +74,7 @@ public func run_DictionaryOfAnyHashableStrings_lookup(_ n: Int) {
for _ in 1...n {
for i in 0 ..< keys.count {
let key = keys[i]
CheckResults((workload[key] as! Int) == i)
check((workload[key] as! Int) == i)
}
}
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -21,7 +21,7 @@ let numberMap = Dictionary(uniqueKeysWithValues: zip(1...size, 1...size))
let boxedNums = (1...size).lazy.map { Box($0) }
let boxedNumMap = Dictionary(uniqueKeysWithValues: zip(boxedNums, boxedNums))
public let DictionaryRemove = [
public let benchmarks = [
BenchmarkInfo(name: "DictionaryRemove",
runFunction: remove, tags: t, legacyFactor: 10),
BenchmarkInfo(name: "DictionaryRemoveOfObjects",
@@ -44,18 +44,18 @@ class Box<T : Hashable> : Hashable {
}
}
func remove(N: Int) {
for _ in 1...100*N {
func remove(n: Int) {
for _ in 1...100*n {
var dict = numberMap
for i in 1...size { dict.removeValue(forKey: i) }
CheckResults(dict.isEmpty)
check(dict.isEmpty)
}
}
func removeObjects(N: Int) {
for _ in 1...10*N {
func removeObjects(n: Int) {
for _ in 1...10*n {
var dict = boxedNumMap
for i in 1...size { dict.removeValue(forKey: Box(i)) }
CheckResults(dict.isEmpty)
check(dict.isEmpty)
}
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -12,7 +12,7 @@
import TestsUtils
public let DictionarySubscriptDefault = [
public let benchmarks = [
BenchmarkInfo(name: "DictionarySubscriptDefaultMutation",
runFunction: run_DictionarySubscriptDefaultMutation,
tags: [.validation, .api, .Dictionary]),
@@ -29,8 +29,8 @@ public let DictionarySubscriptDefault = [
]
@inline(never)
public func run_DictionarySubscriptDefaultMutation(_ N: Int) {
for _ in 1...N {
public func run_DictionarySubscriptDefaultMutation(_ n: Int) {
for _ in 1...n {
var dict = [Int: Int]()
@@ -38,14 +38,14 @@ public func run_DictionarySubscriptDefaultMutation(_ N: Int) {
dict[i % 100, default: 0] += 1
}
CheckResults(dict.count == 100)
CheckResults(dict[0]! == 100)
check(dict.count == 100)
check(dict[0]! == 100)
}
}
@inline(never)
public func run_DictionarySubscriptDefaultMutationArray(_ N: Int) {
for _ in 1...N {
public func run_DictionarySubscriptDefaultMutationArray(_ n: Int) {
for _ in 1...n {
var dict = [Int: [Int]]()
@@ -53,8 +53,8 @@ public func run_DictionarySubscriptDefaultMutationArray(_ N: Int) {
dict[i % 100, default: []].append(i)
}
CheckResults(dict.count == 100)
CheckResults(dict[0]!.count == 100)
check(dict.count == 100)
check(dict[0]!.count == 100)
}
}
@@ -91,8 +91,8 @@ class Box<T : Hashable> : Hashable, P {
}
@inline(never)
public func run_DictionarySubscriptDefaultMutationOfObjects(_ N: Int) {
for _ in 1...N {
public func run_DictionarySubscriptDefaultMutationOfObjects(_ n: Int) {
for _ in 1...n {
var dict = [Box<Int>: Box<Int>]()
@@ -100,14 +100,14 @@ public func run_DictionarySubscriptDefaultMutationOfObjects(_ N: Int) {
dict[Box(i % 5), default: Box(0)].mutateValue { $0 += 1 }
}
CheckResults(dict.count == 5)
CheckResults(dict[Box(0)]!.value == 100)
check(dict.count == 5)
check(dict[Box(0)]!.value == 100)
}
}
@inline(never)
public func run_DictionarySubscriptDefaultMutationArrayOfObjects(_ N: Int) {
for _ in 1...N {
public func run_DictionarySubscriptDefaultMutationArrayOfObjects(_ n: Int) {
for _ in 1...n {
var dict = [Box<Int>: [Box<Int>]]()
@@ -115,7 +115,7 @@ public func run_DictionarySubscriptDefaultMutationArrayOfObjects(_ N: Int) {
dict[Box(i % 5), default: []].append(Box(i))
}
CheckResults(dict.count == 5)
CheckResults(dict[Box(0)]!.count == 100)
check(dict.count == 5)
check(dict[Box(0)]!.count == 100)
}
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -21,7 +21,7 @@ let boxedNumMap = Dictionary(uniqueKeysWithValues: zip(boxedNums, boxedNums))
let t: [BenchmarkCategory] = [.validation, .api, .Dictionary, .cpubench]
public let DictionarySwap = [
public let benchmarks = [
BenchmarkInfo(name: "DictionarySwap",
runFunction: swap, tags: t, legacyFactor: 4),
BenchmarkInfo(name: "DictionarySwapOfObjects",
@@ -54,49 +54,49 @@ class Box<T : Hashable> : Hashable {
}
}
func swap(N: Int) {
func swap(n: Int) {
var dict = numberMap
var swapped = false
for _ in 1...2500*N {
for _ in 1...2500*n {
(dict[25], dict[75]) = (dict[75]!, dict[25]!)
swapped = !swapped
CheckResults(swappedCorrectly(swapped, dict[25]!, dict[75]!))
check(swappedCorrectly(swapped, dict[25]!, dict[75]!))
}
}
func swapObjects(N: Int) {
func swapObjects(n: Int) {
var dict = boxedNumMap
var swapped = false
for _ in 1...250*N {
for _ in 1...250*n {
let b1 = Box(25)
let b2 = Box(75)
(dict[b1], dict[b2]) = (dict[b2]!, dict[b1]!)
swapped = !swapped
CheckResults(swappedCorrectly(swapped,
check(swappedCorrectly(swapped,
dict[Box(25)]!.value, dict[Box(75)]!.value))
}
}
func swapAt(N: Int) {
func swapAt(n: Int) {
var dict = numberMap
var swapped = false
for _ in 1...2500*N {
for _ in 1...2500*n {
let i25 = dict.index(forKey: 25)!
let i75 = dict.index(forKey: 75)!
dict.values.swapAt(i25, i75)
swapped = !swapped
CheckResults(swappedCorrectly(swapped, dict[25]!, dict[75]!))
check(swappedCorrectly(swapped, dict[25]!, dict[75]!))
}
}
func swapAtObjects(N: Int) {
func swapAtObjects(n: Int) {
var dict = boxedNumMap
var swapped = false
for _ in 1...1000*N {
for _ in 1...1000*n {
let i25 = dict.index(forKey: Box(25))!
let i75 = dict.index(forKey: Box(75))!
dict.values.swapAt(i25, i75)
swapped = !swapped
CheckResults(swappedCorrectly(swapped,
check(swappedCorrectly(swapped,
dict[Box(25)]!.value, dict[Box(75)]!.value))
}}

View File

@@ -15,7 +15,7 @@
import TestsUtils
import _Differentiation
public let Differentiation = [
public let benchmarks = [
BenchmarkInfo(
name: "DifferentiationIdentity",
runFunction: run_DifferentiationIdentity,
@@ -35,21 +35,21 @@ public let Differentiation = [
]
@inline(never)
public func run_DifferentiationIdentity(N: Int) {
public func run_DifferentiationIdentity(n: Int) {
func f(_ x: Float) -> Float {
x
}
for _ in 0..<1000*N {
for _ in 0..<1000*n {
blackHole(valueWithGradient(at: 1, of: f))
}
}
@inline(never)
public func run_DifferentiationSquare(N: Int) {
public func run_DifferentiationSquare(n: Int) {
func f(_ x: Float) -> Float {
x * x
}
for _ in 0..<1000*N {
for _ in 0..<1000*n {
blackHole(valueWithGradient(at: 1, of: f))
}
}
@@ -57,7 +57,7 @@ public func run_DifferentiationSquare(N: Int) {
let onesArray: [Float] = Array(repeating: 1, count: 50)
@inline(never)
public func run_DifferentiationArraySum(N: Int) {
public func run_DifferentiationArraySum(n: Int) {
func sum(_ array: [Float]) -> Float {
var result: Float = 0
for i in withoutDerivative(at: 0..<array.count) {
@@ -65,7 +65,7 @@ public func run_DifferentiationArraySum(N: Int) {
}
return result
}
for _ in 0..<N {
for _ in 0..<n {
blackHole(valueWithGradient(at: onesArray, of: sum))
}
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -13,7 +13,7 @@
import TestsUtils
let t: [BenchmarkCategory] = [.api]
public let Diffing = [
public let benchmarks = [
BenchmarkInfo(
name: "Diffing.Same",
runFunction: { diff($0, from: longPangram, to: longPangram) },
@@ -60,9 +60,9 @@ let loremIpsum = Array("Lorem ipsum dolor sit amet, consectetur adipiscing elit,
let unabridgedLorem = Array("Lorem ipsum, quia dolor sit amet consectetur adipisci[ng] velit, sed quia non-numquam [do] eius modi tempora inci[di]dunt, ut labore et dolore magnam aliqua.")
let loremReversed = Array(loremIpsum.reversed())
@inline(never) func diff(_ N: Int, from older: [Character], to newer: [Character]) {
@inline(never) func diff(_ n: Int, from older: [Character], to newer: [Character]) {
if #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) {
for _ in 1...N {
for _ in 1...n {
blackHole(newer.difference(from: older))
}
}

View File

@@ -16,20 +16,21 @@ import TestsUtils
// described in Myers (1986). The Diffing benchmark tracks the performance
// of `Collection.difference(from:to:)`.
public let DiffingMyers = BenchmarkInfo(
name: "Diffing.Myers.Similar",
runFunction: run_Myers,
tags: [.algorithm],
setUpFunction: { blackHole((loremIpsum, unabridgedLorem)) })
public let benchmarks =
BenchmarkInfo(
name: "Diffing.Myers.Similar",
runFunction: run_Myers,
tags: [.algorithm],
setUpFunction: { blackHole((loremIpsum, unabridgedLorem)) })
let loremIpsum = Array("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.")
let unabridgedLorem = Array("Lorem ipsum, quia dolor sit amet consectetur adipisci[ng] velit, sed quia non-numquam [do] eius modi tempora inci[di]dunt, ut labore et dolore magnam aliqua.")
@inline(never)
public func run_Myers(N: Int) {
public func run_Myers(n: Int) {
if #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) {
for _ in 1...N {
for _ in 1...n {
blackHole(myers(from: unabridgedLorem, to: loremIpsum, using: ==))
}
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -24,7 +24,7 @@ let suffixCount = sequenceCount - dropCount
let sumCount = suffixCount * (2 * sequenceCount - suffixCount - 1) / 2
let array: [Int] = Array(0..<sequenceCount)
public let DropFirst = [
public let benchmarks = [
BenchmarkInfo(
name: "DropFirstCountableRange",
runFunction: run_DropFirstCountableRange,
@@ -86,157 +86,157 @@ public let DropFirst = [
]
@inline(never)
public func run_DropFirstCountableRange(_ N: Int) {
public func run_DropFirstCountableRange(_ n: Int) {
let s = 0..<sequenceCount
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.dropFirst(dropCount) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
@inline(never)
public func run_DropFirstSequence(_ N: Int) {
public func run_DropFirstSequence(_ n: Int) {
let s = sequence(first: 0) { $0 < sequenceCount - 1 ? $0 &+ 1 : nil }
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.dropFirst(dropCount) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
@inline(never)
public func run_DropFirstAnySequence(_ N: Int) {
public func run_DropFirstAnySequence(_ n: Int) {
let s = AnySequence(sequence(first: 0) { $0 < sequenceCount - 1 ? $0 &+ 1 : nil })
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.dropFirst(dropCount) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
@inline(never)
public func run_DropFirstAnySeqCntRange(_ N: Int) {
public func run_DropFirstAnySeqCntRange(_ n: Int) {
let s = AnySequence(0..<sequenceCount)
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.dropFirst(dropCount) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
@inline(never)
public func run_DropFirstAnySeqCRangeIter(_ N: Int) {
public func run_DropFirstAnySeqCRangeIter(_ n: Int) {
let s = AnySequence((0..<sequenceCount).makeIterator())
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.dropFirst(dropCount) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
@inline(never)
public func run_DropFirstAnyCollection(_ N: Int) {
public func run_DropFirstAnyCollection(_ n: Int) {
let s = AnyCollection(0..<sequenceCount)
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.dropFirst(dropCount) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
@inline(never)
public func run_DropFirstArray(_ N: Int) {
public func run_DropFirstArray(_ n: Int) {
let s = array
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.dropFirst(dropCount) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
@inline(never)
public func run_DropFirstCountableRangeLazy(_ N: Int) {
public func run_DropFirstCountableRangeLazy(_ n: Int) {
let s = (0..<sequenceCount).lazy
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.dropFirst(dropCount) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
@inline(never)
public func run_DropFirstSequenceLazy(_ N: Int) {
public func run_DropFirstSequenceLazy(_ n: Int) {
let s = (sequence(first: 0) { $0 < sequenceCount - 1 ? $0 &+ 1 : nil }).lazy
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.dropFirst(dropCount) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
@inline(never)
public func run_DropFirstAnySequenceLazy(_ N: Int) {
public func run_DropFirstAnySequenceLazy(_ n: Int) {
let s = (AnySequence(sequence(first: 0) { $0 < sequenceCount - 1 ? $0 &+ 1 : nil })).lazy
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.dropFirst(dropCount) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
@inline(never)
public func run_DropFirstAnySeqCntRangeLazy(_ N: Int) {
public func run_DropFirstAnySeqCntRangeLazy(_ n: Int) {
let s = (AnySequence(0..<sequenceCount)).lazy
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.dropFirst(dropCount) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
@inline(never)
public func run_DropFirstAnySeqCRangeIterLazy(_ N: Int) {
public func run_DropFirstAnySeqCRangeIterLazy(_ n: Int) {
let s = (AnySequence((0..<sequenceCount).makeIterator())).lazy
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.dropFirst(dropCount) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
@inline(never)
public func run_DropFirstAnyCollectionLazy(_ N: Int) {
public func run_DropFirstAnyCollectionLazy(_ n: Int) {
let s = (AnyCollection(0..<sequenceCount)).lazy
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.dropFirst(dropCount) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
@inline(never)
public func run_DropFirstArrayLazy(_ N: Int) {
public func run_DropFirstArrayLazy(_ n: Int) {
let s = (array).lazy
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.dropFirst(dropCount) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -43,7 +43,7 @@ def lazy (NameExpr) : return (NameExpr[0] + 'Lazy', '(' + NameExpr[1] + ').lazy'
Sequences = Sequences + list(map(lazy, Sequences))
}%
public let DropFirst = [
public let benchmarks = [
% for (Name, Expr) in Sequences:
BenchmarkInfo(
name: "DropFirst${Name}",
@@ -56,14 +56,14 @@ public let DropFirst = [
% for (Name, Expr) in Sequences:
@inline(never)
public func run_DropFirst${Name}(_ N: Int) {
public func run_DropFirst${Name}(_ n: Int) {
let s = ${Expr}
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.dropFirst(dropCount) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
% end

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -24,7 +24,7 @@ let dropCount = sequenceCount - prefixCount
let sumCount = prefixCount * (prefixCount - 1) / 2
let array: [Int] = Array(0..<sequenceCount)
public let DropLast = [
public let benchmarks = [
BenchmarkInfo(
name: "DropLastCountableRange",
runFunction: run_DropLastCountableRange,
@@ -86,157 +86,157 @@ public let DropLast = [
]
@inline(never)
public func run_DropLastCountableRange(_ N: Int) {
public func run_DropLastCountableRange(_ n: Int) {
let s = 0..<sequenceCount
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.dropLast(dropCount) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
@inline(never)
public func run_DropLastSequence(_ N: Int) {
public func run_DropLastSequence(_ n: Int) {
let s = sequence(first: 0) { $0 < sequenceCount - 1 ? $0 &+ 1 : nil }
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.dropLast(dropCount) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
@inline(never)
public func run_DropLastAnySequence(_ N: Int) {
public func run_DropLastAnySequence(_ n: Int) {
let s = AnySequence(sequence(first: 0) { $0 < sequenceCount - 1 ? $0 &+ 1 : nil })
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.dropLast(dropCount) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
@inline(never)
public func run_DropLastAnySeqCntRange(_ N: Int) {
public func run_DropLastAnySeqCntRange(_ n: Int) {
let s = AnySequence(0..<sequenceCount)
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.dropLast(dropCount) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
@inline(never)
public func run_DropLastAnySeqCRangeIter(_ N: Int) {
public func run_DropLastAnySeqCRangeIter(_ n: Int) {
let s = AnySequence((0..<sequenceCount).makeIterator())
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.dropLast(dropCount) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
@inline(never)
public func run_DropLastAnyCollection(_ N: Int) {
public func run_DropLastAnyCollection(_ n: Int) {
let s = AnyCollection(0..<sequenceCount)
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.dropLast(dropCount) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
@inline(never)
public func run_DropLastArray(_ N: Int) {
public func run_DropLastArray(_ n: Int) {
let s = array
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.dropLast(dropCount) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
@inline(never)
public func run_DropLastCountableRangeLazy(_ N: Int) {
public func run_DropLastCountableRangeLazy(_ n: Int) {
let s = (0..<sequenceCount).lazy
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.dropLast(dropCount) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
@inline(never)
public func run_DropLastSequenceLazy(_ N: Int) {
public func run_DropLastSequenceLazy(_ n: Int) {
let s = (sequence(first: 0) { $0 < sequenceCount - 1 ? $0 &+ 1 : nil }).lazy
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.dropLast(dropCount) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
@inline(never)
public func run_DropLastAnySequenceLazy(_ N: Int) {
public func run_DropLastAnySequenceLazy(_ n: Int) {
let s = (AnySequence(sequence(first: 0) { $0 < sequenceCount - 1 ? $0 &+ 1 : nil })).lazy
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.dropLast(dropCount) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
@inline(never)
public func run_DropLastAnySeqCntRangeLazy(_ N: Int) {
public func run_DropLastAnySeqCntRangeLazy(_ n: Int) {
let s = (AnySequence(0..<sequenceCount)).lazy
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.dropLast(dropCount) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
@inline(never)
public func run_DropLastAnySeqCRangeIterLazy(_ N: Int) {
public func run_DropLastAnySeqCRangeIterLazy(_ n: Int) {
let s = (AnySequence((0..<sequenceCount).makeIterator())).lazy
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.dropLast(dropCount) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
@inline(never)
public func run_DropLastAnyCollectionLazy(_ N: Int) {
public func run_DropLastAnyCollectionLazy(_ n: Int) {
let s = (AnyCollection(0..<sequenceCount)).lazy
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.dropLast(dropCount) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
@inline(never)
public func run_DropLastArrayLazy(_ N: Int) {
public func run_DropLastArrayLazy(_ n: Int) {
let s = (array).lazy
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.dropLast(dropCount) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -43,7 +43,7 @@ def lazy (NameExpr) : return (NameExpr[0] + 'Lazy', '(' + NameExpr[1] + ').lazy'
Sequences = Sequences + list(map(lazy, Sequences))
}%
public let DropLast = [
public let benchmarks = [
% for (Name, Expr) in Sequences:
BenchmarkInfo(
name: "DropLast${Name}",
@@ -56,14 +56,14 @@ public let DropLast = [
% for (Name, Expr) in Sequences:
@inline(never)
public func run_DropLast${Name}(_ N: Int) {
public func run_DropLast${Name}(_ n: Int) {
let s = ${Expr}
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.dropLast(dropCount) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
% end

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -24,7 +24,7 @@ let suffixCount = sequenceCount - dropCount
let sumCount = suffixCount * (2 * sequenceCount - suffixCount - 1) / 2
let array: [Int] = Array(0..<sequenceCount)
public let DropWhile = [
public let benchmarks = [
BenchmarkInfo(
name: "DropWhileCountableRange",
runFunction: run_DropWhileCountableRange,
@@ -86,157 +86,157 @@ public let DropWhile = [
]
@inline(never)
public func run_DropWhileCountableRange(_ N: Int) {
public func run_DropWhileCountableRange(_ n: Int) {
let s = 0..<sequenceCount
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.drop(while: {$0 < dropCount} ) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
@inline(never)
public func run_DropWhileSequence(_ N: Int) {
public func run_DropWhileSequence(_ n: Int) {
let s = sequence(first: 0) { $0 < sequenceCount - 1 ? $0 &+ 1 : nil }
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.drop(while: {$0 < dropCount} ) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
@inline(never)
public func run_DropWhileAnySequence(_ N: Int) {
public func run_DropWhileAnySequence(_ n: Int) {
let s = AnySequence(sequence(first: 0) { $0 < sequenceCount - 1 ? $0 &+ 1 : nil })
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.drop(while: {$0 < dropCount} ) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
@inline(never)
public func run_DropWhileAnySeqCntRange(_ N: Int) {
public func run_DropWhileAnySeqCntRange(_ n: Int) {
let s = AnySequence(0..<sequenceCount)
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.drop(while: {$0 < dropCount} ) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
@inline(never)
public func run_DropWhileAnySeqCRangeIter(_ N: Int) {
public func run_DropWhileAnySeqCRangeIter(_ n: Int) {
let s = AnySequence((0..<sequenceCount).makeIterator())
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.drop(while: {$0 < dropCount} ) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
@inline(never)
public func run_DropWhileAnyCollection(_ N: Int) {
public func run_DropWhileAnyCollection(_ n: Int) {
let s = AnyCollection(0..<sequenceCount)
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.drop(while: {$0 < dropCount} ) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
@inline(never)
public func run_DropWhileArray(_ N: Int) {
public func run_DropWhileArray(_ n: Int) {
let s = array
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.drop(while: {$0 < dropCount} ) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
@inline(never)
public func run_DropWhileCountableRangeLazy(_ N: Int) {
public func run_DropWhileCountableRangeLazy(_ n: Int) {
let s = (0..<sequenceCount).lazy
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.drop(while: {$0 < dropCount} ) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
@inline(never)
public func run_DropWhileSequenceLazy(_ N: Int) {
public func run_DropWhileSequenceLazy(_ n: Int) {
let s = (sequence(first: 0) { $0 < sequenceCount - 1 ? $0 &+ 1 : nil }).lazy
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.drop(while: {$0 < dropCount} ) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
@inline(never)
public func run_DropWhileAnySequenceLazy(_ N: Int) {
public func run_DropWhileAnySequenceLazy(_ n: Int) {
let s = (AnySequence(sequence(first: 0) { $0 < sequenceCount - 1 ? $0 &+ 1 : nil })).lazy
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.drop(while: {$0 < dropCount} ) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
@inline(never)
public func run_DropWhileAnySeqCntRangeLazy(_ N: Int) {
public func run_DropWhileAnySeqCntRangeLazy(_ n: Int) {
let s = (AnySequence(0..<sequenceCount)).lazy
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.drop(while: {$0 < dropCount} ) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
@inline(never)
public func run_DropWhileAnySeqCRangeIterLazy(_ N: Int) {
public func run_DropWhileAnySeqCRangeIterLazy(_ n: Int) {
let s = (AnySequence((0..<sequenceCount).makeIterator())).lazy
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.drop(while: {$0 < dropCount} ) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
@inline(never)
public func run_DropWhileAnyCollectionLazy(_ N: Int) {
public func run_DropWhileAnyCollectionLazy(_ n: Int) {
let s = (AnyCollection(0..<sequenceCount)).lazy
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.drop(while: {$0 < dropCount} ) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
@inline(never)
public func run_DropWhileArrayLazy(_ N: Int) {
public func run_DropWhileArrayLazy(_ n: Int) {
let s = (array).lazy
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.drop(while: {$0 < dropCount} ) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -43,7 +43,7 @@ def lazy (NameExpr) : return (NameExpr[0] + 'Lazy', '(' + NameExpr[1] + ').lazy'
Sequences = Sequences + list(map(lazy, Sequences))
}%
public let DropWhile = [
public let benchmarks = [
% for (Name, Expr) in Sequences:
BenchmarkInfo(
name: "DropWhile${Name}",
@@ -56,14 +56,14 @@ public let DropWhile = [
% for (Name, Expr) in Sequences:
@inline(never)
public func run_DropWhile${Name}(_ N: Int) {
public func run_DropWhile${Name}(_ n: Int) {
let s = ${Expr}
for _ in 1...20*N {
for _ in 1...20*n {
var result = 0
for element in s.drop(while: {$0 < dropCount} ) {
result += element
}
CheckResults(result == sumCount)
check(result == sumCount)
}
}
% end

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -12,11 +12,12 @@
import TestsUtils
public let ErrorHandling = BenchmarkInfo(
name: "ErrorHandling",
runFunction: run_ErrorHandling,
tags: [.validation, .exceptions],
legacyFactor: 10)
public let benchmarks =
BenchmarkInfo(
name: "ErrorHandling",
runFunction: run_ErrorHandling,
tags: [.validation, .exceptions],
legacyFactor: 10)
enum PizzaError : Error {
case Pepperoni, Olives, Anchovy
@@ -35,8 +36,8 @@ func doSomething() throws -> String {
}
@inline(never)
public func run_ErrorHandling(_ N: Int) {
for _ in 1...500*N {
public func run_ErrorHandling(_ n: Int) {
for _ in 1...500*n {
do {
_ = try doSomething()
} catch _ {

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -17,7 +17,7 @@
import TestsUtils
public let Exclusivity = [
public let benchmarks = [
// At -Onone
// 25% swift_beginAccess
// 15% tlv_get_addr
@@ -63,12 +63,12 @@ public var globalCounter: Int = 0
// - Whole module analysis can remove exclusivity checks (> 10x speedup now, 4x speedup with runtime in OS).
// (The global's "public" qualifier should make the benchmark immune to this optimization.)
@inline(never)
public func run_accessGlobal(_ N: Int) {
public func run_accessGlobal(_ n: Int) {
globalCounter = 0
for _ in 1...10000*N {
for _ in 1...10000*n {
globalCounter += 1
}
CheckResults(globalCounter == 10000*N)
check(globalCounter == 10000*n)
}
// Measure memory access checks on a class property.
@@ -96,12 +96,12 @@ func updateClass(_ c: C) {
// TODO: Replacing materializeForSet accessors with yield-once
// accessors should make the callback overhead go away.
@inline(never)
public func run_accessInMatSet(_ N: Int) {
public func run_accessInMatSet(_ n: Int) {
let c = C()
for _ in 1...10000*N {
for _ in 1...10000*n {
updateClass(c)
}
CheckResults(c.counter == 10000*N)
check(c.counter == 10000*n)
}
// Measure nested access to independent objects.
@@ -122,7 +122,7 @@ func update(a: inout Var, b: inout Var, c: inout Var, d: inout Var) {
}
@inline(never)
public func run_accessIndependent(_ N: Int) {
public func run_accessIndependent(_ n: Int) {
var a = Var()
var b = Var()
var c = Var()
@@ -130,9 +130,9 @@ public func run_accessIndependent(_ N: Int) {
let updateVars = {
update(a: &a, b: &b, c: &c, d: &d)
}
for _ in 1...1000*N {
for _ in 1...1000*n {
updateVars()
}
CheckResults(a.val == 1000*N && b.val == 1000*N && c.val == 1000*N
&& d.val == 1000*N)
check(a.val == 1000*n && b.val == 1000*n && c.val == 1000*n
&& d.val == 1000*n)
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -30,7 +30,7 @@ import TestsUtils
let t: [BenchmarkCategory] = [.skip]
let ta: [BenchmarkCategory] = [.api, .Array, .skip]
public let ExistentialPerformance: [BenchmarkInfo] = [
public let benchmarks: [BenchmarkInfo] = [
BenchmarkInfo(name: "Existential.method.1x.Ref1",
runFunction: run_method1x, tags: t, setUpFunction: etRef1),
BenchmarkInfo(name: "Existential.method.1x.Ref2",
@@ -464,56 +464,56 @@ func passExistentialTwiceTwoMethodCalls(_ e0: Existential, _ e1: Existential)
return e0.doIt() && e1.doIt() && e0.reallyDoIt() && e1.reallyDoIt()
}
func run_method1x(_ N: Int) {
func run_method1x(_ n: Int) {
let existential = existentialType.init()
for _ in 0 ..< N * 20_000 {
for _ in 0 ..< n * 20_000 {
if !existential.doIt() {
fatalError("expected true")
}
}
}
func run_method2x(_ N: Int) {
func run_method2x(_ n: Int) {
let existential = existentialType.init()
for _ in 0 ..< N * 20_000 {
for _ in 0 ..< n * 20_000 {
if !existential.doIt() || !existential.reallyDoIt() {
fatalError("expected true")
}
}
}
func run_Pass_method1x(_ N: Int) {
func run_Pass_method1x(_ n: Int) {
let existential = existentialType.init()
let existential2 = existentialType.init()
for _ in 0 ..< N * 20_000 {
for _ in 0 ..< n * 20_000 {
if !passExistentialTwiceOneMethodCall(existential, existential2) {
fatalError("expected true")
}
}
}
func run_Pass_method2x(_ N: Int) {
func run_Pass_method2x(_ n: Int) {
let existential = existentialType.init()
let existential2 = existentialType.init()
for _ in 0 ..< N * 20_000 {
for _ in 0 ..< n * 20_000 {
if !passExistentialTwiceTwoMethodCalls(existential, existential2) {
fatalError("expected true")
}
}
}
func run_Mutating(_ N: Int) {
func run_Mutating(_ n: Int) {
var existential = existentialType.init()
for _ in 0 ..< N * 10_000 {
for _ in 0 ..< n * 10_000 {
if !existential.mutateIt() {
fatalError("expected true")
}
}
}
func run_MutatingAndNonMutating(_ N: Int) {
func run_MutatingAndNonMutating(_ n: Int) {
var existential = existentialType.init()
for _ in 0 ..< N * 10_000 {
for _ in 0 ..< n * 10_000 {
let _ = existential.doIt()
if !existential.mutateIt() {
fatalError("expected true")
@@ -521,16 +521,16 @@ func run_MutatingAndNonMutating(_ N: Int) {
}
}
func run_Array_init(_ N: Int) {
func run_Array_init(_ n: Int) {
for _ in 0 ..< N * 100 {
for _ in 0 ..< n * 100 {
blackHole(Array(repeating: existentialType.init(), count: 128))
}
}
func run_Array_method1x(_ N: Int) {
func run_Array_method1x(_ n: Int) {
let existentialArray = array!
for _ in 0 ..< N * 100 {
for _ in 0 ..< n * 100 {
for elt in existentialArray {
if !elt.doIt() {
fatalError("expected true")
@@ -539,9 +539,9 @@ func run_Array_method1x(_ N: Int) {
}
}
func run_Array_method2x(_ N: Int) {
func run_Array_method2x(_ n: Int) {
let existentialArray = array!
for _ in 0 ..< N * 100 {
for _ in 0 ..< n * 100 {
for elt in existentialArray {
if !elt.doIt() || !elt.reallyDoIt() {
fatalError("expected true")
@@ -550,9 +550,9 @@ func run_Array_method2x(_ N: Int) {
}
}
func run_ArrayMutating(_ N: Int) {
func run_ArrayMutating(_ n: Int) {
var existentialArray = array!
for _ in 0 ..< N * 500 {
for _ in 0 ..< n * 500 {
for i in 0 ..< existentialArray.count {
if !existentialArray[i].mutateIt() {
fatalError("expected true")
@@ -561,18 +561,18 @@ func run_ArrayMutating(_ N: Int) {
}
}
func run_ArrayShift(_ N: Int) {
func run_ArrayShift(_ n: Int) {
var existentialArray = array!
for _ in 0 ..< N * 25 {
for _ in 0 ..< n * 25 {
for i in 0 ..< existentialArray.count-1 {
existentialArray.swapAt(i, i+1)
}
}
}
func run_ArrayConditionalShift(_ N: Int) {
func run_ArrayConditionalShift(_ n: Int) {
var existentialArray = array!
for _ in 0 ..< N * 25 {
for _ in 0 ..< n * 25 {
for i in 0 ..< existentialArray.count-1 {
let curr = existentialArray[i]
if curr.doIt() {

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -133,7 +133,7 @@ def run_function_name(benchmark_name):
r'_\1', control_flow_separator_re.sub( # remove dashes
'', benchmark_name)))
}%
public let ExistentialPerformance: [BenchmarkInfo] = [
public let benchmarks: [BenchmarkInfo] = [
% for (Name, Group, Variant) in Names:
BenchmarkInfo(name: "Existential.${Name}",
runFunction: ${run_function_name(Group)
@@ -239,9 +239,9 @@ func passExistentialTwiceTwoMethodCalls(_ e0: Existential, _ e1: Existential)
}
% for (group, setup, multiple, workload) in Workloads:
${"""
func {0}(_ N: Int) {{
func {0}(_ n: Int) {{
{1}
for _ in 0 ..< N * {2} {{{3} }}
for _ in 0 ..< n * {2} {{{3} }}
}}""".format(run_function_name(group), setup, multiple, workload)}
% end

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -12,36 +12,37 @@
import TestsUtils
public let Fibonacci = BenchmarkInfo(
name: "Fibonacci",
runFunction: run_Fibonacci,
tags: [.algorithm])
public let benchmarks =
BenchmarkInfo(
name: "Fibonacci",
runFunction: run_Fibonacci,
tags: [.algorithm])
func _fibonacci(_ n: Int) -> Int {
if (n <= 2) { return 1 }
return _fibonacci(n - 2) + _fibonacci(n - 1)
}
@inline(never)
func fibonacci(_ n: Int) -> Int {
if (n <= 2) { return 1 }
return fibonacci(n - 2) + fibonacci(n - 1)
}
@inline(never)
func Fibonacci(_ n: Int) -> Int {
// This if prevents optimizer from computing return value of Fibonacci(32)
// This if prevents optimizer from computing return value of fibonacci(32)
// at compile time.
if False() { return 0 }
if getFalse() { return 0 }
if (n <= 2) { return 1 }
return fibonacci(n - 2) + fibonacci(n - 1)
return _fibonacci(n - 2) + _fibonacci(n - 1)
}
@inline(never)
public func run_Fibonacci(_ N: Int) {
public func run_Fibonacci(_ n: Int) {
let n = 24
let ref_result = 46368
var result = 0
for _ in 1...N {
result = Fibonacci(n)
for _ in 1...n {
result = fibonacci(n)
if result != ref_result {
break
}
}
CheckResults(result == ref_result)
check(result == ref_result)
}

View File

@@ -15,12 +15,11 @@ import TestsUtils
// Mini benchmark implementing a naive String search algorithm that
// at the moment shows a lot of ARC traffic.
let t: [BenchmarkCategory] = [.String, .refcount]
let N = 100
var longStringFoFoFoFox: String?
var longArrayFoFoFoFox: [UInt8]?
public let FindStringNaive = [
public let benchmarks = [
BenchmarkInfo(
name: "FindString.Loop1.Substring",
runFunction: runBenchLoop1Substring,

View File

@@ -12,17 +12,19 @@
import TestsUtils
public let FlattenListLoop = BenchmarkInfo(
name: "FlattenListLoop",
runFunction: run_FlattenListLoop,
tags: [.api, .validation],
setUpFunction: { blackHole(inputArray) })
public let benchmarks = [
BenchmarkInfo(
name: "FlattenListLoop",
runFunction: run_FlattenListLoop,
tags: [.api, .validation],
setUpFunction: { blackHole(inputArray) }),
public let FlattenListFlatMap = BenchmarkInfo(
name: "FlattenListFlatMap",
runFunction: run_FlattenListFlatMap,
tags: [.api, .validation],
setUpFunction: { blackHole(inputArray) })
BenchmarkInfo(
name: "FlattenListFlatMap",
runFunction: run_FlattenListFlatMap,
tags: [.api, .validation],
setUpFunction: { blackHole(inputArray) }),
]
let inputArray: [(Int, Int, Int, Int)] = (0..<(1<<16)).map { _ in
(5, 6, 7, 8)
@@ -47,15 +49,15 @@ func flattenLoop(_ input: [(Int, Int, Int, Int)]) -> [Int] {
}
@inline(never)
public func run_FlattenListLoop(_ N: Int) {
for _ in 0..<5*N {
public func run_FlattenListLoop(_ n: Int) {
for _ in 0..<5*n {
blackHole(flattenLoop(inputArray))
}
}
@inline(never)
public func run_FlattenListFlatMap(_ N: Int) {
for _ in 1...5*N {
public func run_FlattenListFlatMap(_ n: Int) {
for _ in 1...5*n {
blackHole(flattenFlatMap(inputArray))
}
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2020 Apple Inc. and the Swift project authors
// Copyright (c) 2020 - 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
@@ -12,7 +12,7 @@
import TestsUtils
public let FloatingPointConversion = [
public let benchmarks = [
BenchmarkInfo(
name: "ConvertFloatingPoint.MockFloat64ToDouble",
runFunction: run_ConvertFloatingPoint_MockFloat64ToDouble,
@@ -165,8 +165,8 @@ let mockFloat64s = doubles.map { MockFloat64($0) }
// See also: test/SILOptimizer/floating_point_conversion.swift
@inline(never)
public func run_ConvertFloatingPoint_MockFloat64ToDouble(_ N: Int) {
for _ in 0..<(N * 100) {
public func run_ConvertFloatingPoint_MockFloat64ToDouble(_ n: Int) {
for _ in 0..<(n * 100) {
for element in mockFloat64s {
let f = Double(identity(element))
blackHole(f)
@@ -182,8 +182,8 @@ func convert<
}
@inline(never)
public func run_ConvertFloatingPoint_MockFloat64Exactly(_ N: Int) {
for _ in 0..<(N * 25) {
public func run_ConvertFloatingPoint_MockFloat64Exactly(_ n: Int) {
for _ in 0..<(n * 25) {
for element in mockFloat64s {
let f = convert(exactly: identity(element), to: Double.self)
blackHole(f)
@@ -192,8 +192,8 @@ public func run_ConvertFloatingPoint_MockFloat64Exactly(_ N: Int) {
}
@inline(never)
public func run_ConvertFloatingPoint_MockFloat64Exactly2(_ N: Int) {
for _ in 0..<(N * 25) {
public func run_ConvertFloatingPoint_MockFloat64Exactly2(_ n: Int) {
for _ in 0..<(n * 25) {
for element in mockFloat64s {
let f = convert(exactly: identity(element), to: MockFloat32.self)
blackHole(f)
@@ -202,8 +202,8 @@ public func run_ConvertFloatingPoint_MockFloat64Exactly2(_ N: Int) {
}
@inline(never)
public func run_ConvertFloatingPoint_MockFloat64ToInt64(_ N: Int) {
for _ in 0..<(N * 1000) {
public func run_ConvertFloatingPoint_MockFloat64ToInt64(_ n: Int) {
for _ in 0..<(n * 1000) {
for element in mockFloat64s {
let i = Int64(identity(element))
blackHole(i)

View File

@@ -15,7 +15,7 @@
import TestsUtils
public let FloatingPointParsing = [
public let benchmarks = [
BenchmarkInfo(
name: "ParseFloat.Float.Exp",
runFunction: run_ParseFloatExp,
@@ -221,8 +221,8 @@ let float80UniformWorkload = [
]
@inline(__always)
public func parseFloatWorkload<T : LosslessStringConvertible>(_ N: Int, workload: [String], type: T.Type) {
for _ in 0..<N {
public func parseFloatWorkload<T : LosslessStringConvertible>(_ n: Int, workload: [String], type: T.Type) {
for _ in 0..<n {
for element in workload {
let f = T(element)
blackHole(f)
@@ -231,43 +231,43 @@ public func parseFloatWorkload<T : LosslessStringConvertible>(_ N: Int, workload
}
@inline(never)
public func run_ParseFloatExp(_ N: Int) {
parseFloatWorkload(N, workload: floatExpWorkload, type: Float.self)
public func run_ParseFloatExp(_ n: Int) {
parseFloatWorkload(n, workload: floatExpWorkload, type: Float.self)
}
@inline(never)
public func run_ParseDoubleExp(_ N: Int) {
parseFloatWorkload(N, workload: doubleExpWorkload, type: Double.self)
public func run_ParseDoubleExp(_ n: Int) {
parseFloatWorkload(n, workload: doubleExpWorkload, type: Double.self)
}
@inline(never)
public func run_ParseFloat80Exp(_ N: Int) {
public func run_ParseFloat80Exp(_ n: Int) {
#if canImport(Darwin) || os(Linux)
// On Darwin, long double is Float80 on x86, and Double otherwise.
// On Linux, Float80 is at aleast available on x86.
#if arch(x86_64) || arch(i386)
parseFloatWorkload(N, workload: float80ExpWorkload, type: Float80.self)
parseFloatWorkload(n, workload: float80ExpWorkload, type: Float80.self)
#endif // x86
#endif // Darwin/Linux
}
@inline(never)
public func run_ParseFloatUniform(_ N: Int) {
parseFloatWorkload(N, workload: floatUniformWorkload, type: Float.self)
public func run_ParseFloatUniform(_ n: Int) {
parseFloatWorkload(n, workload: floatUniformWorkload, type: Float.self)
}
@inline(never)
public func run_ParseDoubleUniform(_ N: Int) {
parseFloatWorkload(N, workload: doubleUniformWorkload, type: Double.self)
public func run_ParseDoubleUniform(_ n: Int) {
parseFloatWorkload(n, workload: doubleUniformWorkload, type: Double.self)
}
@inline(never)
public func run_ParseFloat80Uniform(_ N: Int) {
public func run_ParseFloat80Uniform(_ n: Int) {
#if canImport(Darwin) || os(Linux)
// On Darwin, long double is Float80 on x86, and Double otherwise.
// On Linux, Float80 is at aleast available on x86.
#if arch(x86_64) || arch(i386)
parseFloatWorkload(N, workload: float80UniformWorkload, type: Float80.self)
parseFloatWorkload(n, workload: float80UniformWorkload, type: Float80.self)
#endif // x86
#endif // Darwin/Linux
}

View File

@@ -15,7 +15,7 @@
import TestsUtils
public let FloatingPointPrinting = [
public let benchmarks = [
BenchmarkInfo(
name: "FloatingPointPrinting_Float_description_small",
runFunction: run_FloatingPointPrinting_Float_description_small,
@@ -83,9 +83,9 @@ public let FloatingPointPrinting = [
// the decimal:
@inline(never)
public func run_FloatingPointPrinting_Float_description_small(_ N: Int) {
public func run_FloatingPointPrinting_Float_description_small(_ n: Int) {
let count = 1_000
for _ in 0..<N {
for _ in 0..<n {
for i in 1...count {
let f = Float(i) / 101.0
blackHole(f.description)
@@ -94,9 +94,9 @@ public func run_FloatingPointPrinting_Float_description_small(_ N: Int) {
}
@inline(never)
public func run_FloatingPointPrinting_Double_description_small(_ N: Int) {
public func run_FloatingPointPrinting_Double_description_small(_ n: Int) {
let count = 1_000
for _ in 0..<N {
for _ in 0..<n {
for i in 1...count {
let f = Double(i) / 101.0
blackHole(f.description)
@@ -105,13 +105,13 @@ public func run_FloatingPointPrinting_Double_description_small(_ N: Int) {
}
@inline(never)
public func run_FloatingPointPrinting_Float80_description_small(_ N: Int) {
public func run_FloatingPointPrinting_Float80_description_small(_ n: Int) {
#if canImport(Darwin) || os(Linux)
// On Darwin, long double is Float80 on x86, and Double otherwise.
// On Linux, Float80 is at aleast available on x86.
#if arch(x86_64) || arch(i386)
let count = 1_000
for _ in 0..<N {
for _ in 0..<n {
for i in 1...count {
let f = Float80(i) / 101.0
blackHole(f.description)
@@ -125,10 +125,10 @@ public func run_FloatingPointPrinting_Float80_description_small(_ N: Int) {
// the full range of the type:
@inline(never)
public func run_FloatingPointPrinting_Float_description_uniform(_ N: Int) {
public func run_FloatingPointPrinting_Float_description_uniform(_ n: Int) {
let count = 1_000
let step = UInt32.max / UInt32(count)
for _ in 0..<N {
for _ in 0..<n {
for i in 0..<count {
let raw = UInt32(i) * step
let f = Float(bitPattern: raw)
@@ -138,10 +138,10 @@ public func run_FloatingPointPrinting_Float_description_uniform(_ N: Int) {
}
@inline(never)
public func run_FloatingPointPrinting_Double_description_uniform(_ N: Int) {
public func run_FloatingPointPrinting_Double_description_uniform(_ n: Int) {
let count = 1_000
let step = UInt64.max / UInt64(count)
for _ in 0..<N {
for _ in 0..<n {
for i in 0..<count {
let raw = UInt64(i) * step
let f = Double(bitPattern: raw)
@@ -151,14 +151,14 @@ public func run_FloatingPointPrinting_Double_description_uniform(_ N: Int) {
}
@inline(never)
public func run_FloatingPointPrinting_Float80_description_uniform(_ N: Int) {
public func run_FloatingPointPrinting_Float80_description_uniform(_ n: Int) {
#if canImport(Darwin) || os(Linux)
// On Darwin, long double is Float80 on x86, and Double otherwise.
// On Linux, Float80 is at aleast available on x86.
#if arch(x86_64) || arch(i386)
let count = 1_000
let step = UInt64.max / UInt64(count)
for _ in 0..<N {
for _ in 0..<n {
for i in 0..<count {
let fraction = UInt64(i) * step
let exponent = UInt(i) % 32768
@@ -175,10 +175,10 @@ public func run_FloatingPointPrinting_Float80_description_uniform(_ N: Int) {
// result.
@inline(never)
public func run_FloatingPointPrinting_Float_interpolated(_ N: Int) {
public func run_FloatingPointPrinting_Float_interpolated(_ n: Int) {
let count = 500
let step = UInt32.max / UInt32(count)
for _ in 0..<N {
for _ in 0..<n {
for i in 0..<count {
let raw = UInt32(i) * step
let f = Float(bitPattern: raw)
@@ -188,10 +188,10 @@ public func run_FloatingPointPrinting_Float_interpolated(_ N: Int) {
}
@inline(never)
public func run_FloatingPointPrinting_Double_interpolated(_ N: Int) {
public func run_FloatingPointPrinting_Double_interpolated(_ n: Int) {
let count = 500
let step = UInt64.max / UInt64(count)
for _ in 0..<N {
for _ in 0..<n {
for i in 0..<count {
let raw = UInt64(i) * step
let f = Double(bitPattern: raw)
@@ -201,14 +201,14 @@ public func run_FloatingPointPrinting_Double_interpolated(_ N: Int) {
}
@inline(never)
public func run_FloatingPointPrinting_Float80_interpolated(_ N: Int) {
public func run_FloatingPointPrinting_Float80_interpolated(_ n: Int) {
#if canImport(Darwin) || os(Linux)
// On Darwin, long double is Float80 on x86, and Double otherwise.
// On Linux, Float80 is at aleast available on x86.
#if arch(x86_64) || arch(i386)
let count = 500
let step = UInt64.max / UInt64(count)
for _ in 0..<N {
for _ in 0..<n {
for i in 0..<count {
let fraction = UInt64(i) * step
let exponent = UInt(i) % 32768

View File

@@ -18,7 +18,7 @@ import TestsUtils
// Swift's performance switching over enums with substantial amounts of associated data.
//
public let HTTP2StateMachine = [
public let benchmarks = [
BenchmarkInfo(
name: "HTTP2StateMachine",
runFunction: run_HTTP2StateMachine,
@@ -380,11 +380,11 @@ func testPushingRequests() -> Bool {
}
@inline(never)
func run_HTTP2StateMachine(_ N: Int) {
for _ in 0 ..< 1000000 * N {
CheckResults(testSimpleRequestResponse())
CheckResults(testPushedRequests())
CheckResults(testPushingRequests())
func run_HTTP2StateMachine(_ n: Int) {
for _ in 0 ..< 1000000 * n {
check(testSimpleRequestResponse())
check(testPushedRequests())
check(testPushingRequests())
}
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -14,11 +14,12 @@
// <rdar://problem/22151932>
import TestsUtils
public let Hanoi = BenchmarkInfo(
name: "Hanoi",
runFunction: run_Hanoi,
tags: [.validation, .algorithm],
legacyFactor: 10)
public let benchmarks =
BenchmarkInfo(
name: "Hanoi",
runFunction: run_Hanoi,
tags: [.validation, .algorithm],
legacyFactor: 10)
struct Move {
var from: String
@@ -45,8 +46,8 @@ class TowersOfHanoi {
}
@inline(never)
public func run_Hanoi(_ N: Int) {
for _ in 1...10*N {
public func run_Hanoi(_ n: Int) {
for _ in 1...10*n {
let hanoi: TowersOfHanoi = TowersOfHanoi()
hanoi.solve(10, start: "A", auxiliary: "B", end: "C")
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -15,11 +15,13 @@
// http://en.wikipedia.org/wiki/SHA-1
import TestsUtils
public let HashTest = BenchmarkInfo(
name: "HashTest",
runFunction: run_HashTest,
tags: [.validation, .algorithm],
legacyFactor: 10)
public let benchmarks = [
BenchmarkInfo(
name: "HashTest",
runFunction: run_HashTest,
tags: [.validation, .algorithm],
legacyFactor: 10),
]
class Hash {
/// C'tor.
@@ -75,7 +77,7 @@ class Hash {
func hashState() -> String {
fatalError("Pure virtual")
}
func hashStateFast(_ Res: inout [UInt8]) {
func hashStateFast(_ res: inout [UInt8]) {
fatalError("Pure virtual")
}
@@ -84,30 +86,30 @@ class Hash {
fatalError("Pure virtual")
}
var HexTbl = ["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"]
var hexTable = ["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"]
final
var HexTblFast : [UInt8] = [48,49,50,51,52,53,54,55,56,57,97,98,99,100,101,102]
var hexTableFast : [UInt8] = [48,49,50,51,52,53,54,55,56,57,97,98,99,100,101,102]
/// Convert a 4-byte integer to a hex string.
final
func toHex(_ In: UInt32) -> String {
var In = In
var Res = ""
func toHex(_ input: UInt32) -> String {
var input = input
var res = ""
for _ in 0..<8 {
Res = HexTbl[Int(In & 0xF)] + Res
In = In >> 4
res = hexTable[Int(input & 0xF)] + res
input = input >> 4
}
return Res
return res
}
final
func toHexFast(_ In: UInt32, _ Res: inout Array<UInt8>, _ Index : Int) {
var In = In
func toHexFast(_ input: UInt32, _ res: inout Array<UInt8>, _ index : Int) {
var input = input
for i in 0..<4 {
// Convert one byte each iteration.
Res[Index + 2*i] = HexTblFast[Int(In >> 4) & 0xF]
Res[Index + 2*i + 1] = HexTblFast[Int(In & 0xF)]
In = In >> 8
res[index + 2*i] = hexTableFast[Int(input >> 4) & 0xF]
res[index + 2*i + 1] = hexTableFast[Int(input & 0xF)]
input = input >> 8
}
}
@@ -171,11 +173,11 @@ class MD5 : Hash {
dataLength = 0
}
func appendBytes(_ Val: Int, _ Message: inout Array<UInt8>, _ Offset : Int) {
Message[Offset] = UInt8(truncatingIfNeeded: Val)
Message[Offset + 1] = UInt8(truncatingIfNeeded: Val >> 8)
Message[Offset + 2] = UInt8(truncatingIfNeeded: Val >> 16)
Message[Offset + 3] = UInt8(truncatingIfNeeded: Val >> 24)
func appendBytes(_ val: Int, _ message: inout Array<UInt8>, _ offset : Int) {
message[offset] = UInt8(truncatingIfNeeded: val)
message[offset + 1] = UInt8(truncatingIfNeeded: val >> 8)
message[offset + 2] = UInt8(truncatingIfNeeded: val >> 16)
message[offset + 3] = UInt8(truncatingIfNeeded: val >> 24)
}
override
@@ -208,11 +210,11 @@ class MD5 : Hash {
dataLength += 8
}
func toUInt32(_ Message: Array<UInt8>, _ Offset: Int) -> UInt32 {
let first = UInt32(Message[Offset + 0])
let second = UInt32(Message[Offset + 1]) << 8
let third = UInt32(Message[Offset + 2]) << 16
let fourth = UInt32(Message[Offset + 3]) << 24
func toUInt32(_ message: Array<UInt8>, _ offset: Int) -> UInt32 {
let first = UInt32(message[offset + 0])
let second = UInt32(message[offset + 1]) << 8
let third = UInt32(message[offset + 2]) << 16
let fourth = UInt32(message[offset + 3]) << 24
return first | second | third | fourth
}
@@ -265,36 +267,36 @@ class MD5 : Hash {
h3 = d &+ h3
}
func reverseBytes(_ In: UInt32) -> UInt32 {
let B0 = (In >> 0 ) & 0xFF
let B1 = (In >> 8 ) & 0xFF
let B2 = (In >> 16) & 0xFF
let B3 = (In >> 24) & 0xFF
return (B0 << 24) | (B1 << 16) | (B2 << 8) | B3
func reverseBytes(_ input: UInt32) -> UInt32 {
let b0 = (input >> 0 ) & 0xFF
let b1 = (input >> 8 ) & 0xFF
let b2 = (input >> 16) & 0xFF
let b3 = (input >> 24) & 0xFF
return (b0 << 24) | (b1 << 16) | (b2 << 8) | b3
}
override
func hashState() -> String {
var S = ""
var s = ""
for h in [h0, h1, h2, h3] {
S += toHex(reverseBytes(h))
s += toHex(reverseBytes(h))
}
return S
return s
}
override
func hashStateFast(_ Res: inout [UInt8]) {
func hashStateFast(_ res: inout [UInt8]) {
#if !NO_RANGE
var Idx: Int = 0
var idx: Int = 0
for h in [h0, h1, h2, h3] {
toHexFast(h, &Res, Idx)
Idx += 8
toHexFast(h, &res, idx)
idx += 8
}
#else
toHexFast(h0, &Res, 0)
toHexFast(h1, &Res, 8)
toHexFast(h2, &Res, 16)
toHexFast(h3, &Res, 24)
toHexFast(h0, &res, 0)
toHexFast(h1, &res, 8)
toHexFast(h2, &res, 16)
toHexFast(h3, &res, 24)
#endif
}
@@ -375,50 +377,50 @@ class SHA1 : Hash {
dataLength = 0
var A = h0
var B = h1
var C = h2
var D = h3
var E = h4
var K: UInt32, F: UInt32
var a = h0
var b = h1
var c = h2
var d = h3
var e = h4
var k: UInt32, f: UInt32
for t in 0..<80 {
if t < 20 {
K = 0x5a827999
F = (B & C) | ((B ^ 0xFFFFFFFF) & D)
k = 0x5a827999
f = (b & c) | ((b ^ 0xFFFFFFFF) & d)
} else if t < 40 {
K = 0x6ed9eba1
F = B ^ C ^ D
k = 0x6ed9eba1
f = b ^ c ^ d
} else if t < 60 {
K = 0x8f1bbcdc
F = (B & C) | (B & D) | (C & D)
k = 0x8f1bbcdc
f = (b & c) | (b & d) | (c & d)
} else {
K = 0xca62c1d6
F = B ^ C ^ D
k = 0xca62c1d6
f = b ^ c ^ d
}
let Temp: UInt32 = rol(A,5) &+ F &+ E &+ w[t] &+ K
let temp: UInt32 = rol(a,5) &+ f &+ e &+ w[t] &+ k
E = D
D = C
C = rol(B,30)
B = A
A = Temp
e = d
d = c
c = rol(b,30)
b = a
a = temp
}
h0 = h0 &+ A
h1 = h1 &+ B
h2 = h2 &+ C
h3 = h3 &+ D
h4 = h4 &+ E
h0 = h0 &+ a
h1 = h1 &+ b
h2 = h2 &+ c
h3 = h3 &+ d
h4 = h4 &+ e
}
override
func hashState() -> String {
var Res: String = ""
var res: String = ""
for state in [h0, h1, h2, h3, h4] {
Res += toHex(state)
res += toHex(state)
}
return Res
return res
}
}
@@ -522,12 +524,12 @@ class SHA256 : Hash {
var h = h7
for i in 0..<64 {
let S1 = ror(e, 6) ^ ror(e, 11) ^ ror(e, 25)
let s1 = ror(e, 6) ^ ror(e, 11) ^ ror(e, 25)
let ch = (e & f) ^ ((~e) & g)
let temp1 = h &+ S1 &+ ch &+ k[i] &+ w[i]
let S0 = ror(a, 2) ^ ror(a, 13) ^ ror(a, 22)
let temp1 = h &+ s1 &+ ch &+ k[i] &+ w[i]
let s0 = ror(a, 2) ^ ror(a, 13) ^ ror(a, 22)
let maj = (a & b) ^ (a & c) ^ (b & c)
let temp2 = S0 &+ maj
let temp2 = s0 &+ maj
h = g
g = f
@@ -551,11 +553,11 @@ class SHA256 : Hash {
override
func hashState() -> String {
var Res: String = ""
var res: String = ""
for state in [h0, h1, h2, h3, h4, h5, h6, h7] {
Res += toHex(state)
res += toHex(state)
}
return Res
return res
}
}
@@ -568,104 +570,104 @@ func == (lhs: [UInt8], rhs: [UInt8]) -> Bool {
}
@inline(never)
public func run_HashTest(_ N: Int) {
let TestMD5 = ["" : "d41d8cd98f00b204e9800998ecf8427e",
public func run_HashTest(_ n: Int) {
let testMD5 = ["" : "d41d8cd98f00b204e9800998ecf8427e",
"The quick brown fox jumps over the lazy dog." : "e4d909c290d0fb1ca068ffaddf22cbd0",
"The quick brown fox jumps over the lazy cog." : "68aa5deab43e4df2b5e1f80190477fb0"]
let TestSHA1 = ["" : "da39a3ee5e6b4b0d3255bfef95601890afd80709",
let testSHA1 = ["" : "da39a3ee5e6b4b0d3255bfef95601890afd80709",
"The quick brown fox jumps over the lazy dog" : "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12",
"The quick brown fox jumps over the lazy cog" : "de9f2c7fd25e1b3afad3e85a0bd17d9b100db4b3"]
let TestSHA256 = ["" : "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
let testSHA256 = ["" : "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"The quick brown fox jumps over the lazy dog" : "d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592",
"The quick brown fox jumps over the lazy dog." : "ef537f25c895bfa782526529a9b63d97aa631564d5d789c2b765448c8635fb6c"]
let size = 50
for _ in 1...N {
for _ in 1...n {
// Check for precomputed values.
let MD = MD5()
for (K, V) in TestMD5 {
MD.update(K)
CheckResults(MD.digest() == V)
MD.reset()
let md = MD5()
for (k, v) in testMD5 {
md.update(k)
check(md.digest() == v)
md.reset()
}
// Check that we don't crash on large strings.
var S: String = ""
var s: String = ""
for _ in 1...size {
S += "a"
MD.reset()
MD.update(S)
s += "a"
md.reset()
md.update(s)
}
// Check that the order in which we push values does not change the result.
MD.reset()
var L: String = ""
md.reset()
var l: String = ""
for _ in 1...size {
L += "a"
MD.update("a")
l += "a"
md.update("a")
}
let MD2 = MD5()
MD2.update(L)
CheckResults(MD.digest() == MD2.digest())
let md2 = MD5()
md2.update(l)
check(md.digest() == md2.digest())
// Test the famous MD5 collision from 2009: http://www.mscs.dal.ca/~selinger/md5collision/
let Src1 : [UInt8] =
// Test the famous md5 collision from 2009: http://www.mscs.dal.ca/~selinger/md5collision/
let src1 : [UInt8] =
[0xd1, 0x31, 0xdd, 0x02, 0xc5, 0xe6, 0xee, 0xc4, 0x69, 0x3d, 0x9a, 0x06, 0x98, 0xaf, 0xf9, 0x5c, 0x2f, 0xca, 0xb5, 0x87, 0x12, 0x46, 0x7e, 0xab, 0x40, 0x04, 0x58, 0x3e, 0xb8, 0xfb, 0x7f, 0x89,
0x55, 0xad, 0x34, 0x06, 0x09, 0xf4, 0xb3, 0x02, 0x83, 0xe4, 0x88, 0x83, 0x25, 0x71, 0x41, 0x5a, 0x08, 0x51, 0x25, 0xe8, 0xf7, 0xcd, 0xc9, 0x9f, 0xd9, 0x1d, 0xbd, 0xf2, 0x80, 0x37, 0x3c, 0x5b,
0xd8, 0x82, 0x3e, 0x31, 0x56, 0x34, 0x8f, 0x5b, 0xae, 0x6d, 0xac, 0xd4, 0x36, 0xc9, 0x19, 0xc6, 0xdd, 0x53, 0xe2, 0xb4, 0x87, 0xda, 0x03, 0xfd, 0x02, 0x39, 0x63, 0x06, 0xd2, 0x48, 0xcd, 0xa0,
0xe9, 0x9f, 0x33, 0x42, 0x0f, 0x57, 0x7e, 0xe8, 0xce, 0x54, 0xb6, 0x70, 0x80, 0xa8, 0x0d, 0x1e, 0xc6, 0x98, 0x21, 0xbc, 0xb6, 0xa8, 0x83, 0x93, 0x96, 0xf9, 0x65, 0x2b, 0x6f, 0xf7, 0x2a, 0x70]
let Src2 : [UInt8] =
let src2 : [UInt8] =
[0xd1, 0x31, 0xdd, 0x02, 0xc5, 0xe6, 0xee, 0xc4, 0x69, 0x3d, 0x9a, 0x06, 0x98, 0xaf, 0xf9, 0x5c, 0x2f, 0xca, 0xb5, 0x07, 0x12, 0x46, 0x7e, 0xab, 0x40, 0x04, 0x58, 0x3e, 0xb8, 0xfb, 0x7f, 0x89,
0x55, 0xad, 0x34, 0x06, 0x09, 0xf4, 0xb3, 0x02, 0x83, 0xe4, 0x88, 0x83, 0x25, 0xf1, 0x41, 0x5a, 0x08, 0x51, 0x25, 0xe8, 0xf7, 0xcd, 0xc9, 0x9f, 0xd9, 0x1d, 0xbd, 0x72, 0x80, 0x37, 0x3c, 0x5b,
0xd8, 0x82, 0x3e, 0x31, 0x56, 0x34, 0x8f, 0x5b, 0xae, 0x6d, 0xac, 0xd4, 0x36, 0xc9, 0x19, 0xc6, 0xdd, 0x53, 0xe2, 0x34, 0x87, 0xda, 0x03, 0xfd, 0x02, 0x39, 0x63, 0x06, 0xd2, 0x48, 0xcd, 0xa0,
0xe9, 0x9f, 0x33, 0x42, 0x0f, 0x57, 0x7e, 0xe8, 0xce, 0x54, 0xb6, 0x70, 0x80, 0x28, 0x0d, 0x1e, 0xc6, 0x98, 0x21, 0xbc, 0xb6, 0xa8, 0x83, 0x93, 0x96, 0xf9, 0x65, 0xab, 0x6f, 0xf7, 0x2a, 0x70]
let H1 = MD5()
let H2 = MD5()
let h1 = MD5()
let h2 = MD5()
H1.update(Src1)
H2.update(Src2)
let A1 = H1.digest()
let A2 = H2.digest()
CheckResults(A1 == A2)
CheckResults(A1 == "79054025255fb1a26e4bc422aef54eb4")
H1.reset()
H2.reset()
h1.update(src1)
h2.update(src2)
let a1 = h1.digest()
let a2 = h2.digest()
check(a1 == a2)
check(a1 == "79054025255fb1a26e4bc422aef54eb4")
h1.reset()
h2.reset()
let SH = SHA1()
let SH256 = SHA256()
for (K, V) in TestSHA1 {
SH.update(K)
CheckResults(SH.digest() == V)
SH.reset()
let sh = SHA1()
let sh256 = SHA256()
for (k, v) in testSHA1 {
sh.update(k)
check(sh.digest() == v)
sh.reset()
}
for (K, V) in TestSHA256 {
SH256.update(K)
CheckResults(SH256.digest() == V)
SH256.reset()
for (k, v) in testSHA256 {
sh256.update(k)
check(sh256.digest() == v)
sh256.reset()
}
// Check that we don't crash on large strings.
S = ""
s = ""
for _ in 1...size {
S += "a"
SH.reset()
SH.update(S)
s += "a"
sh.reset()
sh.update(s)
}
// Check that the order in which we push values does not change the result.
SH.reset()
L = ""
sh.reset()
l = ""
for _ in 1...size {
L += "a"
SH.update("a")
l += "a"
sh.update("a")
}
let SH2 = SHA1()
SH2.update(L)
CheckResults(SH.digest() == SH2.digest())
let sh2 = SHA1()
sh2.update(l)
check(sh.digest() == sh2.digest())
}
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -14,17 +14,18 @@
// <rdar://problem/17384894>
import TestsUtils
public let Histogram = BenchmarkInfo(
name: "Histogram",
runFunction: run_Histogram,
tags: [.validation, .algorithm])
public let benchmarks =
BenchmarkInfo(
name: "Histogram",
runFunction: run_Histogram,
tags: [.validation, .algorithm])
typealias rrggbb_t = UInt32
func output_sorted_sparse_rgb_histogram<S: Sequence>(_ samples: S, _ N: Int)
func output_sorted_sparse_rgb_histogram<S: Sequence>(_ samples: S, _ n: Int)
where S.Element == rrggbb_t {
var histogram = Dictionary<rrggbb_t, Int>()
for _ in 1...50*N {
for _ in 1...50*n {
for sample in samples { // This part is really awful, I agree
let i = histogram.index(forKey: sample)
histogram[sample] = (i != nil ? histogram[i!].1 : 0) + 1
@@ -115,6 +116,6 @@ let samples: [rrggbb_t] = [
]
@inline(never)
public func run_Histogram(_ N: Int) {
output_sorted_sparse_rgb_histogram(samples, N)
public func run_Histogram(_ n: Int) {
output_sorted_sparse_rgb_histogram(samples, n)
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2020 Apple Inc. and the Swift project authors
// Copyright (c) 2020 - 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
@@ -20,7 +20,7 @@ let increasingMaxMiddleIndexPath = indexPath(size, middle: size + 1)
let increasingMinMiddleIndexPath = indexPath(size, middle: -1)
let tags: [BenchmarkCategory] = [.validation, .api, .IndexPath]
public let IndexPathTest = [
public let benchmarks = [
BenchmarkInfo(
name: "IndexPath.Subscript.Mutation",
runFunction: run_IndexPathSubscriptMutation,

View File

@@ -14,7 +14,7 @@ import TestsUtils
let t: [BenchmarkCategory] = [.validation, .api, .String]
public let InsertCharacter = [
public let benchmarks = [
BenchmarkInfo(name: "InsertCharacterEndIndex",
runFunction: run_InsertCharacterEndIndex, tags: t,
setUpFunction: buildWorkload),
@@ -57,13 +57,13 @@ func insertTowardsEndIndex(_ c: Character, in string: String, count: Int) {
}
@inline(never)
func run_InsertCharacterTowardsEndIndex(_ N: Int) {
insertTowardsEndIndex("s", in: str, count: N * 3000)
func run_InsertCharacterTowardsEndIndex(_ n: Int) {
insertTowardsEndIndex("s", in: str, count: n * 3000)
}
@inline(never)
func run_InsertCharacterTowardsEndIndexNonASCII(_ N: Int) {
insertTowardsEndIndex("👩🏼‍💻", in: str, count: N * 1000)
func run_InsertCharacterTowardsEndIndexNonASCII(_ n: Int) {
insertTowardsEndIndex("👩🏼‍💻", in: str, count: n * 1000)
}
// Insert at end index
@@ -78,13 +78,13 @@ func insertAtEndIndex(_ c: Character, in string: String, count: Int) {
}
@inline(never)
func run_InsertCharacterEndIndex(_ N: Int) {
insertAtEndIndex("s", in: str, count: N * 3000)
func run_InsertCharacterEndIndex(_ n: Int) {
insertAtEndIndex("s", in: str, count: n * 3000)
}
@inline(never)
func run_InsertCharacterEndIndexNonASCII(_ N: Int) {
insertAtEndIndex("👩🏾‍🏫", in: str, count: N * 1000)
func run_InsertCharacterEndIndexNonASCII(_ n: Int) {
insertAtEndIndex("👩🏾‍🏫", in: str, count: n * 1000)
}
// Insert at start index
@@ -103,11 +103,11 @@ func insertAtStartIndex(
}
@inline(never)
func run_InsertCharacterStartIndex(_ N: Int) {
insertAtStartIndex("w", in: str, count: N * 15, insertions: 50)
func run_InsertCharacterStartIndex(_ n: Int) {
insertAtStartIndex("w", in: str, count: n * 15, insertions: 50)
}
@inline(never)
func run_InsertCharacterStartIndexNonASCII(_ N: Int) {
insertAtStartIndex("👩🏾‍🏫", in: str, count: N * 75, insertions: 25)
func run_InsertCharacterStartIndexNonASCII(_ n: Int) {
insertAtStartIndex("👩🏾‍🏫", in: str, count: n * 75, insertions: 25)
}

View File

@@ -14,7 +14,7 @@ import TestsUtils
// - Definitions
public let IntegerParsing = [
public let benchmarks = [
// IntSmall
BenchmarkInfo(name: "ParseInt.IntSmall.Decimal",
runFunction: run_ParseIntFromIntSmallDecimal,
@@ -287,296 +287,296 @@ private let uint64UncommonRadixStrings: [String]
// IntSmall
@inline(never)
public func run_ParseIntFromIntSmallDecimal(N: Int) {
public func run_ParseIntFromIntSmallDecimal(n: Int) {
var result: Int = 0
let count = N * 20
let count = n * 20
for _ in 0..<count {
for string in intSmallDecimalStrings {
result &+= Int(string, radix: 10)!
}
}
CheckResults(result == intSmallValuesSum &* Int(count))
check(result == intSmallValuesSum &* Int(count))
}
@inline(never)
public func run_ParseIntFromIntSmallBinary(N: Int) {
public func run_ParseIntFromIntSmallBinary(n: Int) {
var result: Int = 0
let count = N * 20
let count = n * 20
for _ in 0..<count {
for string in intSmallBinaryStrings {
result &+= Int(string, radix: 2)!
}
}
CheckResults(result == intSmallValuesSum &* Int(count))
check(result == intSmallValuesSum &* Int(count))
}
@inline(never)
public func run_ParseIntFromIntSmallHex(N: Int) {
public func run_ParseIntFromIntSmallHex(n: Int) {
var result: Int = 0
let count = N * 20
let count = n * 20
for _ in 0..<count {
for string in intSmallHexStrings {
result &+= Int(string, radix: 16)!
}
}
CheckResults(result == intSmallValuesSum &* Int(count))
check(result == intSmallValuesSum &* Int(count))
}
@inline(never)
public func run_ParseIntFromIntSmallUncommonRadix(N: Int) {
public func run_ParseIntFromIntSmallUncommonRadix(n: Int) {
var result: Int = 0
let count = N * 20
let count = n * 20
for _ in 0..<count {
for string in intSmallUncommonRadixStrings {
result &+= Int(string, radix: 7)!
}
}
CheckResults(result == intSmallValuesSum &* Int(count))
check(result == intSmallValuesSum &* Int(count))
}
// UIntSmall
@inline(never)
public func run_ParseIntFromUIntSmallDecimal(N: Int) {
public func run_ParseIntFromUIntSmallDecimal(n: Int) {
var result: UInt = 0
let count = N * 20
let count = n * 20
for _ in 0..<count {
for string in uintSmallDecimalStrings {
result &+= UInt(string, radix: 10)!
}
}
CheckResults(result == uintSmallValuesSum &* UInt(count))
check(result == uintSmallValuesSum &* UInt(count))
}
@inline(never)
public func run_ParseIntFromUIntSmallBinary(N: Int) {
public func run_ParseIntFromUIntSmallBinary(n: Int) {
var result: UInt = 0
let count = N * 20
let count = n * 20
for _ in 0..<count {
for string in uintSmallBinaryStrings {
result &+= UInt(string, radix: 2)!
}
}
CheckResults(result == uintSmallValuesSum &* UInt(count))
check(result == uintSmallValuesSum &* UInt(count))
}
@inline(never)
public func run_ParseIntFromUIntSmallHex(N: Int) {
public func run_ParseIntFromUIntSmallHex(n: Int) {
var result: UInt = 0
let count = N * 20
let count = n * 20
for _ in 0..<count {
for string in uintSmallHexStrings {
result &+= UInt(string, radix: 16)!
}
}
CheckResults(result == uintSmallValuesSum &* UInt(count))
check(result == uintSmallValuesSum &* UInt(count))
}
@inline(never)
public func run_ParseIntFromUIntSmallUncommonRadix(N: Int) {
public func run_ParseIntFromUIntSmallUncommonRadix(n: Int) {
var result: UInt = 0
let count = N * 20
let count = n * 20
for _ in 0..<count {
for string in uintSmallUncommonRadixStrings {
result &+= UInt(string, radix: 7)!
}
}
CheckResults(result == uintSmallValuesSum &* UInt(count))
check(result == uintSmallValuesSum &* UInt(count))
}
// Int32
@inline(never)
public func run_ParseIntFromInt32Decimal(N: Int) {
public func run_ParseIntFromInt32Decimal(n: Int) {
var result: Int32 = 0
let count = N * 8
let count = n * 8
for _ in 0..<count {
for string in int32DecimalStrings {
result &+= Int32(string, radix: 10)!
}
}
CheckResults(result == int32ValuesSum &* Int32(count))
check(result == int32ValuesSum &* Int32(count))
}
@inline(never)
public func run_ParseIntFromInt32Binary(N: Int) {
public func run_ParseIntFromInt32Binary(n: Int) {
var result: Int32 = 0
let count = N * 8
let count = n * 8
for _ in 0..<count {
for string in int32BinaryStrings {
result &+= Int32(string, radix: 2)!
}
}
CheckResults(result == int32ValuesSum &* Int32(count))
check(result == int32ValuesSum &* Int32(count))
}
@inline(never)
public func run_ParseIntFromInt32Hex(N: Int) {
public func run_ParseIntFromInt32Hex(n: Int) {
var result: Int32 = 0
let count = N * 8
let count = n * 8
for _ in 0..<count {
for string in int32HexStrings {
result &+= Int32(string, radix: 16)!
}
}
CheckResults(result == int32ValuesSum &* Int32(count))
check(result == int32ValuesSum &* Int32(count))
}
@inline(never)
public func run_ParseIntFromInt32UncommonRadix(N: Int) {
public func run_ParseIntFromInt32UncommonRadix(n: Int) {
var result: Int32 = 0
let count = N * 8
let count = n * 8
for _ in 0..<count {
for string in int32UncommonRadixStrings {
result &+= Int32(string, radix: 7)!
}
}
CheckResults(result == int32ValuesSum &* Int32(count))
check(result == int32ValuesSum &* Int32(count))
}
// Int64
@inline(never)
public func run_ParseIntFromInt64Decimal(N: Int) {
public func run_ParseIntFromInt64Decimal(n: Int) {
var result: Int64 = 0
let count = N * 4
let count = n * 4
for _ in 0..<count {
for string in int64DecimalStrings {
result &+= Int64(string, radix: 10)!
}
}
CheckResults(result == int64ValuesSum &* Int64(count))
check(result == int64ValuesSum &* Int64(count))
}
@inline(never)
public func run_ParseIntFromInt64Binary(N: Int) {
public func run_ParseIntFromInt64Binary(n: Int) {
var result: Int64 = 0
let count = N * 4
let count = n * 4
for _ in 0..<count {
for string in int64BinaryStrings {
result &+= Int64(string, radix: 2)!
}
}
CheckResults(result == int64ValuesSum &* Int64(count))
check(result == int64ValuesSum &* Int64(count))
}
@inline(never)
public func run_ParseIntFromInt64Hex(N: Int) {
public func run_ParseIntFromInt64Hex(n: Int) {
var result: Int64 = 0
let count = N * 4
let count = n * 4
for _ in 0..<count {
for string in int64HexStrings {
result &+= Int64(string, radix: 16)!
}
}
CheckResults(result == int64ValuesSum &* Int64(count))
check(result == int64ValuesSum &* Int64(count))
}
@inline(never)
public func run_ParseIntFromInt64UncommonRadix(N: Int) {
public func run_ParseIntFromInt64UncommonRadix(n: Int) {
var result: Int64 = 0
let count = N * 4
let count = n * 4
for _ in 0..<count {
for string in int64UncommonRadixStrings {
result &+= Int64(string, radix: 7)!
}
}
CheckResults(result == int64ValuesSum &* Int64(count))
check(result == int64ValuesSum &* Int64(count))
}
// UInt32
@inline(never)
public func run_ParseIntFromUInt32Decimal(N: Int) {
public func run_ParseIntFromUInt32Decimal(n: Int) {
var result: UInt32 = 0
let count = N * 8
let count = n * 8
for _ in 0..<count {
for string in uint32DecimalStrings {
result &+= UInt32(string, radix: 10)!
}
}
CheckResults(result == uint32ValuesSum &* UInt32(count))
check(result == uint32ValuesSum &* UInt32(count))
}
@inline(never)
public func run_ParseIntFromUInt32Binary(N: Int) {
public func run_ParseIntFromUInt32Binary(n: Int) {
var result: UInt32 = 0
let count = N * 8
let count = n * 8
for _ in 0..<count {
for string in uint32BinaryStrings {
result &+= UInt32(string, radix: 2)!
}
}
CheckResults(result == uint32ValuesSum &* UInt32(count))
check(result == uint32ValuesSum &* UInt32(count))
}
@inline(never)
public func run_ParseIntFromUInt32Hex(N: Int) {
public func run_ParseIntFromUInt32Hex(n: Int) {
var result: UInt32 = 0
let count = N * 8
let count = n * 8
for _ in 0..<count {
for string in uint32HexStrings {
result &+= UInt32(string, radix: 16)!
}
}
CheckResults(result == uint32ValuesSum &* UInt32(count))
check(result == uint32ValuesSum &* UInt32(count))
}
@inline(never)
public func run_ParseIntFromUInt32UncommonRadix(N: Int) {
public func run_ParseIntFromUInt32UncommonRadix(n: Int) {
var result: UInt32 = 0
let count = N * 8
let count = n * 8
for _ in 0..<count {
for string in uint32UncommonRadixStrings {
result &+= UInt32(string, radix: 7)!
}
}
CheckResults(result == uint32ValuesSum &* UInt32(count))
check(result == uint32ValuesSum &* UInt32(count))
}
// UInt64
@inline(never)
public func run_ParseIntFromUInt64Decimal(N: Int) {
public func run_ParseIntFromUInt64Decimal(n: Int) {
var result: UInt64 = 0
let count = N * 4
let count = n * 4
for _ in 0..<count {
for string in uint64DecimalStrings {
result &+= UInt64(string, radix: 10)!
}
}
CheckResults(result == uint64ValuesSum &* UInt64(count))
check(result == uint64ValuesSum &* UInt64(count))
}
@inline(never)
public func run_ParseIntFromUInt64Binary(N: Int) {
public func run_ParseIntFromUInt64Binary(n: Int) {
var result: UInt64 = 0
let count = N * 4
let count = n * 4
for _ in 0..<count {
for string in uint64BinaryStrings {
result &+= UInt64(string, radix: 2)!
}
}
CheckResults(result == uint64ValuesSum &* UInt64(count))
check(result == uint64ValuesSum &* UInt64(count))
}
@inline(never)
public func run_ParseIntFromUInt64Hex(N: Int) {
public func run_ParseIntFromUInt64Hex(n: Int) {
var result: UInt64 = 0
let count = N * 4
let count = n * 4
for _ in 0..<count {
for string in uint64HexStrings {
result &+= UInt64(string, radix: 16)!
}
}
CheckResults(result == uint64ValuesSum &* UInt64(count))
check(result == uint64ValuesSum &* UInt64(count))
}
@inline(never)
public func run_ParseIntFromUInt64UncommonRadix(N: Int) {
public func run_ParseIntFromUInt64UncommonRadix(n: Int) {
var result: UInt64 = 0
let count = N * 4
let count = n * 4
for _ in 0..<count {
for string in uint64UncommonRadixStrings {
result &+= UInt64(string, radix: 7)!
}
}
CheckResults(result == uint64ValuesSum &* UInt64(count))
check(result == uint64ValuesSum &* UInt64(count))
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -15,10 +15,11 @@ import TestsUtils
// A micro-benchmark for recursive divide and conquer problems.
// The program performs integration via Gaussian Quadrature
public let IntegrateTest = BenchmarkInfo(
name: "Integrate",
runFunction: run_Integrate,
tags: [.validation, .algorithm])
public let benchmarks =
BenchmarkInfo(
name: "Integrate",
runFunction: run_Integrate,
tags: [.validation, .algorithm])
class Integrate {
static let epsilon = 1.0e-9
@@ -54,19 +55,19 @@ class Integrate {
}
@inline(never)
public func run_Integrate(_ N: Int) {
public func run_Integrate(_ n: Int) {
let obj = Integrate(f: { x in (x*x + 1.0) * x})
let left = 0.0
let right = 10.0
let ref_result = 2550.0
let bound = 0.0001
var result = 0.0
for _ in 1...N {
for _ in 1...n {
result = obj.computeArea(left, right:right)
if abs(result - ref_result) > bound {
break
}
}
CheckResults(abs(result - ref_result) < bound)
check(abs(result - ref_result) < bound)
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -13,11 +13,12 @@
import TestsUtils
import Foundation
public let IterateData = BenchmarkInfo(
name: "IterateData",
runFunction: run_IterateData,
tags: [.validation, .api, .Data],
setUpFunction: { blackHole(data) })
public let benchmarks =
BenchmarkInfo(
name: "IterateData",
runFunction: run_IterateData,
tags: [.validation, .api, .Data],
setUpFunction: { blackHole(data) })
let data: Data = {
var data = Data(count: 16 * 1024)
@@ -31,8 +32,8 @@ let data: Data = {
}()
@inline(never)
public func run_IterateData(_ N: Int) {
for _ in 1...10*N {
public func run_IterateData(_ n: Int) {
for _ in 1...10*n {
_ = data.reduce(0, &+)
}
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -13,15 +13,16 @@
// This test tests the performance of ASCII Character comparison.
import TestsUtils
public let Join = BenchmarkInfo(
name: "Join",
runFunction: run_Join,
tags: [.validation, .api, .String, .Array])
public let benchmarks =
BenchmarkInfo(
name: "Join",
runFunction: run_Join,
tags: [.validation, .api, .String, .Array])
@inline(never)
public func run_Join(_ N: Int) {
public func run_Join(_ n: Int) {
var array: [String] = []
for x in 0..<1000 * N {
for x in 0..<1000 * n {
array.append(String(x))
}
_ = array.joined(separator: "")

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -14,7 +14,7 @@
// collections.
import TestsUtils
public let LazyFilter = [
public let benchmarks = [
BenchmarkInfo(name: "LazilyFilteredArrays2",
runFunction: run_LazilyFilteredArrays,
tags: [.validation, .api, .Array],
@@ -35,39 +35,39 @@ public let LazyFilter = [
]
@inline(never)
public func run_LazilyFilteredRange(_ N: Int) {
public func run_LazilyFilteredRange(_ n: Int) {
var res = 123
let c = (1..<100_000).lazy.filter { $0 % 7 == 0 }
for _ in 1...N {
for _ in 1...n {
res += Array(c).count
res -= Array(c).count
}
CheckResults(res == 123)
check(res == 123)
}
let filteredRange = (1..<1_000).map({[$0]}).lazy.filter { $0.first! % 7 == 0 }
@inline(never)
public func run_LazilyFilteredArrays(_ N: Int) {
public func run_LazilyFilteredArrays(_ n: Int) {
var res = 123
let c = filteredRange
for _ in 1...N {
for _ in 1...n {
res += Array(c).count
res -= Array(c).count
}
CheckResults(res == 123)
check(res == 123)
}
fileprivate var multiplesOfThree: LazyFilterCollection<Array<Int>>?
@inline(never)
fileprivate func run_LazilyFilteredArrayContains(_ N: Int) {
fileprivate func run_LazilyFilteredArrayContains(_ n: Int) {
let xs = multiplesOfThree!
for _ in 1...N {
for _ in 1...n {
var filteredCount = 0
for candidate in 1..<500 {
filteredCount += xs.contains(candidate) ? 1 : 0
}
CheckResults(filteredCount == 166)
check(filteredCount == 166)
}
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -16,13 +16,14 @@ import TestsUtils
// 47% _swift_retain
// 43% _swift_release
public var LinkedList = BenchmarkInfo(
name: "LinkedList",
runFunction: run_LinkedList,
tags: [.runtime, .cpubench, .refcount],
setUpFunction: { for i in 0..<size { head = Node(n:head, d:i) } },
tearDownFunction: { head = Node(n:nil, d:0) },
legacyFactor: 40)
public let benchmarks =
BenchmarkInfo(
name: "LinkedList",
runFunction: run_LinkedList,
tags: [.runtime, .cpubench, .refcount],
setUpFunction: { for i in 0..<size { head = Node(n:head, d:i) } },
tearDownFunction: { head = Node(n:nil, d:0) },
legacyFactor: 40)
let size = 100
var head = Node(n:nil, d:0)
@@ -38,11 +39,11 @@ final class Node {
}
@inline(never)
public func run_LinkedList(_ N: Int) {
public func run_LinkedList(_ n: Int) {
var sum = 0
let ref_result = size*(size-1)/2
var ptr = head
for _ in 1...125*N {
for _ in 1...125*n {
ptr = head
sum = 0
while let nxt = ptr.next {
@@ -53,5 +54,5 @@ public func run_LinkedList(_ N: Int) {
break
}
}
CheckResults(sum == ref_result)
check(sum == ref_result)
}

View File

@@ -5,18 +5,20 @@
import TestsUtils
public let LuhnAlgoEager = BenchmarkInfo(
name: "LuhnAlgoEager",
runFunction: run_LuhnAlgoEager,
tags: [.algorithm]
)
public let benchmarks = [
BenchmarkInfo(
name: "LuhnAlgoEager",
runFunction: run_LuhnAlgoEager,
tags: [.algorithm]
),
]
@inline(never)
public func run_LuhnAlgoEager(_ N: Int) {
public func run_LuhnAlgoEager(_ n: Int) {
let resultRef = true
var result = false
for _ in 1...100*N {
for _ in 1...100*n {
result = eagerchecksum(ccnum)
if result != resultRef {
@@ -24,7 +26,7 @@ public func run_LuhnAlgoEager(_ N: Int) {
}
}
CheckResults(result == resultRef)
check(result == resultRef)
}
// Another version of the Luhn algorithm, similar to the one found here:

View File

@@ -5,18 +5,20 @@
import TestsUtils
public let LuhnAlgoLazy = BenchmarkInfo(
name: "LuhnAlgoLazy",
runFunction: run_LuhnAlgoLazy,
tags: [.algorithm]
)
public let benchmarks = [
BenchmarkInfo(
name: "LuhnAlgoLazy",
runFunction: run_LuhnAlgoLazy,
tags: [.algorithm]
),
]
@inline(never)
public func run_LuhnAlgoLazy(_ N: Int) {
public func run_LuhnAlgoLazy(_ n: Int) {
let resultRef = true
var result = false
for _ in 1...100*N {
for _ in 1...100*n {
result = lazychecksum(ccnum)
if result != resultRef {
@@ -24,7 +26,7 @@ public func run_LuhnAlgoLazy(_ N: Int) {
}
}
CheckResults(result == resultRef)
check(result == resultRef)
}
// Another version of the Luhn algorithm, similar to the one found here:

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -16,7 +16,7 @@ import Foundation
let t: [BenchmarkCategory] = [.validation, .algorithm]
let ts: [BenchmarkCategory] = [.validation, .algorithm, .String]
public let MapReduce = [
public let benchmarks = [
BenchmarkInfo(name: "MapReduce", runFunction: run_MapReduce, tags: t),
BenchmarkInfo(name: "MapReduceAnyCollection",
runFunction: run_MapReduceAnyCollection, tags: t),
@@ -71,172 +71,172 @@ func boxedNumbers(_ n: Int) { boxedNumbers = (0..<n).map { Box($0) } }
func releaseboxedNumbers() { boxedNumbers = nil }
@inline(never)
public func run_MapReduce(_ N: Int) {
public func run_MapReduce(_ n: Int) {
var numbers = [Int](0..<1000)
var c = 0
for _ in 1...N*100 {
for _ in 1...n*100 {
numbers = numbers.map { $0 &+ 5 }
c += numbers.reduce(0, &+)
}
CheckResults(c != 0)
check(c != 0)
}
@inline(never)
public func run_MapReduceAnyCollection(_ N: Int) {
public func run_MapReduceAnyCollection(_ n: Int) {
let numbers = AnyCollection([Int](0..<1000))
var c = 0
for _ in 1...N*100 {
for _ in 1...n*100 {
let mapped = numbers.map { $0 &+ 5 }
c += mapped.reduce(0, &+)
}
CheckResults(c != 0)
check(c != 0)
}
@inline(never)
public func run_MapReduceAnyCollectionShort(_ N: Int) {
public func run_MapReduceAnyCollectionShort(_ n: Int) {
let numbers = AnyCollection([Int](0..<10))
var c = 0
for _ in 1...N*1_000 {
for _ in 1...n*1_000 {
let mapped = numbers.map { $0 &+ 5 }
c += mapped.reduce(0, &+)
}
CheckResults(c != 0)
check(c != 0)
}
@inline(never)
public func run_MapReduceShort(_ N: Int) {
public func run_MapReduceShort(_ n: Int) {
var numbers = [Int](0..<10)
var c = 0
for _ in 1...N*1_000 {
for _ in 1...n*1_000 {
numbers = numbers.map { $0 &+ 5 }
c += numbers.reduce(0, &+)
}
CheckResults(c != 0)
check(c != 0)
}
@inline(never)
public func run_MapReduceSequence(_ N: Int) {
public func run_MapReduceSequence(_ n: Int) {
let numbers = sequence(first: 0) { $0 < 1000 ? $0 &+ 1 : nil }
var c = 0
for _ in 1...N*100 {
for _ in 1...n*100 {
let mapped = numbers.map { $0 &+ 5 }
c += mapped.reduce(0, &+)
}
CheckResults(c != 0)
check(c != 0)
}
@inline(never)
public func run_MapReduceLazySequence(_ N: Int) {
public func run_MapReduceLazySequence(_ n: Int) {
let numbers = sequence(first: 0) { $0 < 1000 ? $0 &+ 1 : nil }
var c = 0
for _ in 1...N*100 {
for _ in 1...n*100 {
let mapped = numbers.lazy.map { $0 &+ 5 }
c += mapped.reduce(0, &+)
}
CheckResults(c != 0)
check(c != 0)
}
@inline(never)
public func run_MapReduceLazyCollection(_ N: Int) {
public func run_MapReduceLazyCollection(_ n: Int) {
let numbers = [Int](0..<1000)
var c = 0
for _ in 1...N*100 {
for _ in 1...n*100 {
let mapped = numbers.lazy.map { $0 &+ 5 }
c += mapped.reduce(0, &+)
}
CheckResults(c != 0)
check(c != 0)
}
@inline(never)
public func run_MapReduceLazyCollectionShort(_ N: Int) {
public func run_MapReduceLazyCollectionShort(_ n: Int) {
let numbers = [Int](0..<10)
var c = 0
for _ in 1...N*10000 {
for _ in 1...n*10000 {
let mapped = numbers.lazy.map { $0 &+ 5 }
c += mapped.reduce(0, &+)
}
CheckResults(c != 0)
check(c != 0)
}
@inline(never)
public func run_MapReduceString(_ N: Int) {
public func run_MapReduceString(_ n: Int) {
let s = "thequickbrownfoxjumpsoverthelazydogusingasmanycharacteraspossible123456789"
var c: UInt64 = 0
for _ in 1...N*100 {
for _ in 1...n*100 {
c += s.utf8.map { UInt64($0 &+ 5) }.reduce(0, &+)
}
CheckResults(c != 0)
check(c != 0)
}
@inline(never)
public func run_MapReduceShortString(_ N: Int) {
public func run_MapReduceShortString(_ n: Int) {
let s = "12345"
var c: UInt64 = 0
for _ in 1...N*100 {
for _ in 1...n*100 {
c += s.utf8.map { UInt64($0 &+ 5) }.reduce(0, &+)
}
CheckResults(c != 0)
check(c != 0)
}
@inline(never)
public func run_MapReduceNSDecimalNumber(_ N: Int) {
public func run_MapReduceNSDecimalNumber(_ n: Int) {
#if _runtime(_ObjC)
let numbers: [NSDecimalNumber] = decimals
var c = 0
for _ in 1...N*10 {
for _ in 1...n*10 {
let mapped = numbers.map { $0.intValue &+ 5 }
c += mapped.reduce(0, &+)
}
CheckResults(c != 0)
check(c != 0)
#endif
}
@inline(never)
public func run_MapReduceNSDecimalNumberShort(_ N: Int) {
public func run_MapReduceNSDecimalNumberShort(_ n: Int) {
#if _runtime(_ObjC)
let numbers: [NSDecimalNumber] = decimals
var c = 0
for _ in 1...N*1_000 {
for _ in 1...n*1_000 {
let mapped = numbers.map { $0.intValue &+ 5 }
c += mapped.reduce(0, &+)
}
CheckResults(c != 0)
check(c != 0)
#endif
}
@inline(never)
public func run_MapReduceClass(_ N: Int) {
public func run_MapReduceClass(_ n: Int) {
let numbers: [Box] = boxedNumbers
var c = 0
for _ in 1...N*10 {
for _ in 1...n*10 {
let mapped = numbers.map { $0.v &+ 5 }
c += mapped.reduce(0, &+)
}
CheckResults(c != 0)
check(c != 0)
}
@inline(never)
public func run_MapReduceClassShort(_ N: Int) {
public func run_MapReduceClassShort(_ n: Int) {
let numbers: [Box] = boxedNumbers
var c = 0
for _ in 1...N*1_000 {
for _ in 1...n*1_000 {
let mapped = numbers.map { $0.v &+ 5 }
c += mapped.reduce(0, &+)
}
CheckResults(c != 0)
check(c != 0)
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -12,10 +12,11 @@
import TestsUtils
public let Memset = BenchmarkInfo(
name: "Memset",
runFunction: run_Memset,
tags: [.validation])
public let benchmarks =
BenchmarkInfo(
name: "Memset",
runFunction: run_Memset,
tags: [.validation])
@inline(never)
func memset(_ a: inout [Int], _ c: Int) {
@@ -25,11 +26,11 @@ func memset(_ a: inout [Int], _ c: Int) {
}
@inline(never)
public func run_Memset(_ N: Int) {
public func run_Memset(_ n: Int) {
var a = [Int](repeating: 0, count: 10_000)
for _ in 1...50*N {
for _ in 1...50*n {
memset(&a, 1)
memset(&a, 0)
}
CheckResults(a[87] == 0)
check(a[87] == 0)
}

View File

@@ -1,8 +1,8 @@
//===--- Mirror.swift ------------------------------------------------===//
//===--- MirrorTest.swift -------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -13,15 +13,16 @@
// This test measures performance of Mirror and related things.
import TestsUtils
public let TypeName = BenchmarkInfo(
name: "TypeName",
runFunction: run_TypeName,
tags: [.api, .String])
public let MirrorDefault = BenchmarkInfo(
name: "MirrorDefault",
runFunction: run_MirrorDefault,
tags: [.api, .String])
public let benchmarks = [
BenchmarkInfo(
name: "TypeName",
runFunction: run_TypeName,
tags: [.api, .String]),
BenchmarkInfo(
name: "MirrorDefault",
runFunction: run_MirrorDefault,
tags: [.api, .String]),
]
struct S1 { var s: String; var d: Double }
struct S2 { var i: Int; var a: [Range<Int>] }
@@ -37,7 +38,7 @@ struct G<T> { var t: T }
class H<T>: C { var t: T; init(_ t: T) { self.t = t }}
public func run_MirrorDefault(scale: Int) {
let N = 100*scale
let n = 100*scale
let s1 = S1(s: "foo", d: 3.14)
let s2 = S2(i: 42, a: [0..<4])
@@ -50,13 +51,14 @@ public func run_MirrorDefault(scale: Int) {
var str = ""
for _ in 0..<N {
for _ in 0..<n {
str = "\(s1),\(s2),\(c),\(d),\(e),\(f),\(g),\(h)"
blackHole(str)
}
CheckResults(str ==
"S1(s: \"foo\", d: 3.14),S2(i: 42, a: [Range(0..<4)]),Mirror.C,Mirror.D,a,b(99),G<Double>(t: 12.3),Mirror.H<Swift.Array<Swift.Int>>")
check(str ==
"S1(s: \"foo\", d: 3.14),S2(i: 42, a: [Range(0..<4)]),MirrorTest.C,MirrorTest.D,a,b(99),G<Double>(t: 12.3),MirrorTest.H<Swift.Array<Swift.Int>>")
}
func typename<T>(of: T.Type) -> String {
@@ -64,11 +66,11 @@ func typename<T>(of: T.Type) -> String {
}
public func run_TypeName(scale: Int) {
let N = 1_000*scale
let n = 1_000*scale
var a: [String] = []
a.reserveCapacity(16)
for _ in 0..<N {
for _ in 0..<n {
a = []
a.removeAll(keepingCapacity: true)
a.append(typename(of: S1.self))
@@ -101,5 +103,5 @@ public func run_TypeName(scale: Int) {
"Optional<S1>",
"Optional<C>",
]
CheckResults(a == expected)
check(a == expected)
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -19,24 +19,27 @@
// Thus, e = N / Nempty.
import TestsUtils
public let MonteCarloE = BenchmarkInfo(
name: "MonteCarloE",
runFunction: run_MonteCarloE,
tags: [.validation, .algorithm],
legacyFactor: 20)
public let benchmarks =
BenchmarkInfo(
name: "MonteCarloE",
runFunction: run_MonteCarloE,
tags: [.validation, .algorithm],
legacyFactor: 20)
public func run_MonteCarloE(scale: Int) {
let N = 10_000*scale
var intervals = [Bool](repeating: false, count: N)
for _ in 1...N {
let pos = Int(UInt(truncatingIfNeeded: Random())%UInt(N))
var lfsr = LFSR()
let n = 10_000 * scale
var intervals = [Bool](repeating: false, count: n)
for _ in 1...n {
let pos = Int(UInt(truncatingIfNeeded: lfsr.next()) % UInt(n))
intervals[pos] = true
}
let numEmptyIntervals = intervals.filter{!$0}.count
// If there are no empty intervals, then obviously the random generator is
// not 'random' enough.
CheckResults(numEmptyIntervals != N)
let e_estimate = Double(N)/Double(numEmptyIntervals)
check(numEmptyIntervals != n)
let e_estimate = Double(n)/Double(numEmptyIntervals)
let e = 2.71828
CheckResults(abs(e_estimate - e) < 0.2)
check(abs(e_estimate - e) < 0.2)
}

View File

@@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 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
@@ -12,24 +12,27 @@
import TestsUtils
public let MonteCarloPi = BenchmarkInfo(
name: "MonteCarloPi",
runFunction: run_MonteCarloPi,
tags: [.validation, .algorithm],
legacyFactor: 125)
public let benchmarks =
BenchmarkInfo(
name: "MonteCarloPi",
runFunction: run_MonteCarloPi,
tags: [.validation, .algorithm],
legacyFactor: 125)
public func run_MonteCarloPi(scale: Int) {
var rng = LFSR()
var pointsInside = 0
let r = 10000
let N = 4_000*scale
for _ in 1...N {
let x = Int(truncatingIfNeeded: Random())%r
let y = Int(truncatingIfNeeded: Random())%r
let n = 4_000*scale
for _ in 1...n {
let x = Int(truncatingIfNeeded: rng.next()) % r
let y = Int(truncatingIfNeeded: rng.next()) % r
if x*x + y*y < r*r {
pointsInside += 1
}
}
let pi_estimate: Double = Double(pointsInside)*4.0/Double(N)
let pi_estimate: Double = Double(pointsInside)*4.0/Double(n)
let pi = 3.1415
CheckResults(abs(pi_estimate - pi) < 0.2)
check(abs(pi_estimate - pi) < 0.2)
}

Some files were not shown because too many files have changed in this diff Show More