mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[benchmark] Stop capitalizing function and variable names
This commit is contained in:
@@ -296,10 +296,10 @@ public let YourTestName = BenchmarkInfo(
|
||||
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
|
||||
|
||||
@@ -22,8 +22,8 @@ public let CreateObjects = BenchmarkInfo(
|
||||
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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -19,8 +19,8 @@ public let PrimsSplit = BenchmarkInfo(
|
||||
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 +547,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)]!
|
||||
})
|
||||
|
||||
|
||||
@@ -17,6 +17,6 @@ public let {name} = [
|
||||
]
|
||||
|
||||
@inline(never)
|
||||
public func run_{name}(N: Int) {{
|
||||
public func run_{name}(n: Int) {{
|
||||
// TODO
|
||||
}}
|
||||
|
||||
@@ -19,30 +19,30 @@ public let Ackermann = BenchmarkInfo(
|
||||
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 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))
|
||||
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
|
||||
}
|
||||
|
||||
@@ -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()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,9 +54,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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,27 +23,27 @@ public let Array2D = BenchmarkInfo(
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -29,22 +29,22 @@ 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()
|
||||
}
|
||||
@@ -54,9 +54,9 @@ public func run_ArrayValueProp(_ N: Int) {
|
||||
|
||||
@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,28 +64,28 @@ 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()
|
||||
}
|
||||
@@ -93,9 +93,9 @@ public func run_ArrayValueProp2(_ N: Int) {
|
||||
}
|
||||
|
||||
@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()
|
||||
}
|
||||
@@ -103,9 +103,9 @@ public func run_ArrayValueProp3(_ N: Int) {
|
||||
}
|
||||
|
||||
@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()
|
||||
}
|
||||
|
||||
@@ -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]))
|
||||
|
||||
@@ -94,8 +94,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()
|
||||
|
||||
@@ -60,8 +60,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()
|
||||
|
||||
@@ -105,8 +105,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()
|
||||
|
||||
@@ -28,9 +28,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)
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public let ArraySubscript = BenchmarkInfo(
|
||||
legacyFactor: 4)
|
||||
|
||||
@inline(never)
|
||||
public func run_ArraySubscript(_ N: Int) {
|
||||
public func run_ArraySubscript(_ n: Int) {
|
||||
var lfsr = LFSR()
|
||||
|
||||
let numArrays = 50
|
||||
@@ -28,7 +28,7 @@ public func run_ArraySubscript(_ N: Int) {
|
||||
|
||||
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 {
|
||||
|
||||
@@ -196,10 +196,10 @@ 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
|
||||
|
||||
@@ -31,10 +31,10 @@ public let BinaryFloatingPointPropertiesUlp = BenchmarkInfo(
|
||||
)
|
||||
|
||||
@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
|
||||
@@ -45,10 +45,10 @@ public func run_BinaryFloatingPointPropertiesBinade(_ N: Int) {
|
||||
}
|
||||
|
||||
@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)
|
||||
@@ -59,10 +59,10 @@ public func run_BinaryFloatingPointPropertiesNextUp(_ N: Int) {
|
||||
}
|
||||
|
||||
@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)
|
||||
|
||||
@@ -34,13 +34,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))
|
||||
}
|
||||
check(sum == 8 * 1000 * N)
|
||||
check(sum == 8 * 1000 * n)
|
||||
}
|
||||
|
||||
@@ -122,8 +122,8 @@ 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)
|
||||
check(isAscending(sortedArray))
|
||||
|
||||
@@ -44,14 +44,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))
|
||||
}
|
||||
check(s == (2457 &+ 9129 &+ 3333) &* 10000 &* N)
|
||||
check(s == (2457 &+ 9129 &+ 3333) &* 10000 &* n)
|
||||
}
|
||||
|
||||
@@ -37,8 +37,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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,12 @@ public var COWTree = BenchmarkInfo(
|
||||
)
|
||||
|
||||
@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
|
||||
|
||||
@@ -363,9 +363,9 @@ public func buildWorkload() {
|
||||
}
|
||||
|
||||
@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())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,17 +33,17 @@ 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:)))
|
||||
}
|
||||
@@ -51,9 +51,9 @@ public func run_CStringLongAscii(_ N: Int) {
|
||||
}
|
||||
|
||||
@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:)))
|
||||
}
|
||||
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)
|
||||
}
|
||||
check(res == reference)
|
||||
}
|
||||
|
||||
@@ -35,9 +35,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"))
|
||||
|
||||
@@ -32,9 +32,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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -362,7 +362,7 @@ func checkResult(_ plaintext: [UInt8]) {
|
||||
|
||||
@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 +371,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!)
|
||||
}
|
||||
|
||||
@@ -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 }
|
||||
@@ -27,9 +27,9 @@ public func run_ChainedFilterMap(_ N: Int) {
|
||||
}
|
||||
|
||||
@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,8 +40,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()
|
||||
|
||||
@@ -72,8 +72,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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -358,8 +358,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 +376,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 +394,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 +412,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))
|
||||
|
||||
@@ -168,8 +168,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 +179,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 +190,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 +201,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))
|
||||
|
||||
@@ -30,11 +30,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)
|
||||
|
||||
@@ -44,9 +44,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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,12 +12,12 @@ public var Combos = BenchmarkInfo(
|
||||
)
|
||||
|
||||
@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]
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -23,10 +23,10 @@ public let DeadArray = BenchmarkInfo(
|
||||
@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 +37,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)
|
||||
}
|
||||
check(Count == 500)
|
||||
check(count == 500)
|
||||
}
|
||||
|
||||
@@ -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()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ public var DictOfArraysToArrayOfDicts = BenchmarkInfo(
|
||||
)
|
||||
|
||||
@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 +23,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) }
|
||||
}
|
||||
|
||||
@@ -134,11 +134,11 @@ 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
|
||||
@@ -150,14 +150,14 @@ public func run_Dictionary(N: Int) {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
check(count == N*541)
|
||||
check(count == n*541)
|
||||
}
|
||||
|
||||
class Box<T : Hashable> : Hashable {
|
||||
@@ -187,11 +187,11 @@ 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)
|
||||
@@ -203,12 +203,12 @@ public func run_DictionaryOfObjects(N: Int) {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
check(count == N*541)
|
||||
check(count == n*541)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -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)
|
||||
|
||||
@@ -18,7 +18,7 @@ public let Dictionary3 = [
|
||||
]
|
||||
|
||||
@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
|
||||
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
@@ -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 {
|
||||
|
||||
@@ -59,9 +59,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()
|
||||
}
|
||||
|
||||
@@ -55,17 +55,17 @@ 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 {
|
||||
check(identity(d).object(forKey: key) != nil)
|
||||
}
|
||||
@@ -73,9 +73,9 @@ public func run_DictionaryBridgeToObjC_Access(_ N: Int) {
|
||||
}
|
||||
|
||||
@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))
|
||||
check(d2.count == d.count)
|
||||
}
|
||||
|
||||
@@ -34,14 +34,14 @@ public let DictionaryCompactMapValues = [
|
||||
legacyFactor: 54),
|
||||
]
|
||||
|
||||
func compactMapValues(N: Int) {
|
||||
for _ in 1...20*N {
|
||||
func compactMapValues(n: Int) {
|
||||
for _ in 1...20*n {
|
||||
check(smallOddNumMap.compactMapValues({$0}) == compactOddNums)
|
||||
}
|
||||
}
|
||||
|
||||
func compactMapValuesInt(N: Int) {
|
||||
for _ in 1...20*N {
|
||||
func compactMapValuesInt(n: Int) {
|
||||
for _ in 1...20*n {
|
||||
check(oddStringMap.compactMapValues(Int.init) == compactOddNums)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,8 +49,8 @@ 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
|
||||
@@ -62,8 +62,8 @@ func copyKeyValue(N: Int) {
|
||||
// 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 }
|
||||
check(copy.count == dict!.count)
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@ 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 })
|
||||
check(dict.count == 10)
|
||||
check(dict[0]!.count == 1_000)
|
||||
@@ -53,9 +53,9 @@ 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) })
|
||||
check(dict.count == 10)
|
||||
check(dict[Box(0)]!.count == 100)
|
||||
|
||||
@@ -69,11 +69,11 @@ 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) {
|
||||
for _ in 0..<(n * 100) {
|
||||
check(dictionary.keys.contains("42"))
|
||||
check(!dictionary.keys.contains("-1"))
|
||||
}
|
||||
|
||||
@@ -26,8 +26,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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,16 +44,16 @@ 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) }
|
||||
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)) }
|
||||
check(dict.isEmpty)
|
||||
|
||||
@@ -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]()
|
||||
|
||||
@@ -44,8 +44,8 @@ public func run_DictionarySubscriptDefaultMutation(_ N: Int) {
|
||||
}
|
||||
|
||||
@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]]()
|
||||
|
||||
@@ -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>]()
|
||||
|
||||
@@ -106,8 +106,8 @@ public func run_DictionarySubscriptDefaultMutationOfObjects(_ N: Int) {
|
||||
}
|
||||
|
||||
@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>]]()
|
||||
|
||||
|
||||
@@ -54,20 +54,20 @@ 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
|
||||
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]!)
|
||||
@@ -77,10 +77,10 @@ func swapObjects(N: Int) {
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -89,10 +89,10 @@ func swapAt(N: Int) {
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,9 +27,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.")
|
||||
|
||||
@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: ==))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(result == sumCount)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,9 +56,9 @@ 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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(result == sumCount)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,9 +56,9 @@ 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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(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
|
||||
}
|
||||
check(result == sumCount)
|
||||
CheckResults(result == sumCount)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,9 +56,9 @@ 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
|
||||
|
||||
@@ -35,8 +35,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 _ {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
check(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)
|
||||
}
|
||||
check(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()
|
||||
}
|
||||
check(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)
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -17,28 +17,28 @@ public let Fibonacci = BenchmarkInfo(
|
||||
runFunction: run_Fibonacci,
|
||||
tags: [.algorithm])
|
||||
|
||||
func fibonacci(_ n: Int) -> Int {
|
||||
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)
|
||||
func fibonacci(_ n: Int) -> Int {
|
||||
// This if prevents optimizer from computing return value of fibonacci(32)
|
||||
// at compile time.
|
||||
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
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ 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]?
|
||||
|
||||
@@ -47,15 +47,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))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -380,8 +380,8 @@ func testPushingRequests() -> Bool {
|
||||
}
|
||||
|
||||
@inline(never)
|
||||
func run_HTTP2StateMachine(_ N: Int) {
|
||||
for _ in 0 ..< 1000000 * N {
|
||||
func run_HTTP2StateMachine(_ n: Int) {
|
||||
for _ in 0 ..< 1000000 * n {
|
||||
check(testSimpleRequestResponse())
|
||||
check(testPushedRequests())
|
||||
check(testPushingRequests())
|
||||
|
||||
@@ -45,8 +45,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")
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ class Hash {
|
||||
func hashState() -> String {
|
||||
fatalError("Pure virtual")
|
||||
}
|
||||
func hashStateFast(_ Res: inout [UInt8]) {
|
||||
func hashStateFast(_ res: inout [UInt8]) {
|
||||
fatalError("Pure virtual")
|
||||
}
|
||||
|
||||
@@ -84,30 +84,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 +171,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 +208,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 +265,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 +375,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 +522,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 +551,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 +568,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)
|
||||
check(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)
|
||||
check(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()
|
||||
check(A1 == A2)
|
||||
check(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)
|
||||
check(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)
|
||||
check(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)
|
||||
check(SH.digest() == SH2.digest())
|
||||
let sh2 = SHA1()
|
||||
sh2.update(l)
|
||||
check(sh.digest() == sh2.digest())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,10 +21,10 @@ public let Histogram = BenchmarkInfo(
|
||||
|
||||
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 +115,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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -287,9 +287,9 @@ 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)!
|
||||
@@ -299,9 +299,9 @@ public func run_ParseIntFromIntSmallDecimal(N: Int) {
|
||||
}
|
||||
|
||||
@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)!
|
||||
@@ -311,9 +311,9 @@ public func run_ParseIntFromIntSmallBinary(N: Int) {
|
||||
}
|
||||
|
||||
@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)!
|
||||
@@ -323,9 +323,9 @@ public func run_ParseIntFromIntSmallHex(N: Int) {
|
||||
}
|
||||
|
||||
@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)!
|
||||
@@ -336,9 +336,9 @@ public func run_ParseIntFromIntSmallUncommonRadix(N: Int) {
|
||||
|
||||
// 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)!
|
||||
@@ -348,9 +348,9 @@ public func run_ParseIntFromUIntSmallDecimal(N: Int) {
|
||||
}
|
||||
|
||||
@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)!
|
||||
@@ -360,9 +360,9 @@ public func run_ParseIntFromUIntSmallBinary(N: Int) {
|
||||
}
|
||||
|
||||
@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)!
|
||||
@@ -372,9 +372,9 @@ public func run_ParseIntFromUIntSmallHex(N: Int) {
|
||||
}
|
||||
|
||||
@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)!
|
||||
@@ -385,9 +385,9 @@ public func run_ParseIntFromUIntSmallUncommonRadix(N: Int) {
|
||||
|
||||
// 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)!
|
||||
@@ -397,9 +397,9 @@ public func run_ParseIntFromInt32Decimal(N: Int) {
|
||||
}
|
||||
|
||||
@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)!
|
||||
@@ -409,9 +409,9 @@ public func run_ParseIntFromInt32Binary(N: Int) {
|
||||
}
|
||||
|
||||
@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)!
|
||||
@@ -421,9 +421,9 @@ public func run_ParseIntFromInt32Hex(N: Int) {
|
||||
}
|
||||
|
||||
@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)!
|
||||
@@ -434,9 +434,9 @@ public func run_ParseIntFromInt32UncommonRadix(N: Int) {
|
||||
|
||||
// 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)!
|
||||
@@ -446,9 +446,9 @@ public func run_ParseIntFromInt64Decimal(N: Int) {
|
||||
}
|
||||
|
||||
@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)!
|
||||
@@ -458,9 +458,9 @@ public func run_ParseIntFromInt64Binary(N: Int) {
|
||||
}
|
||||
|
||||
@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)!
|
||||
@@ -470,9 +470,9 @@ public func run_ParseIntFromInt64Hex(N: Int) {
|
||||
}
|
||||
|
||||
@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)!
|
||||
@@ -483,9 +483,9 @@ public func run_ParseIntFromInt64UncommonRadix(N: Int) {
|
||||
|
||||
// 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)!
|
||||
@@ -495,9 +495,9 @@ public func run_ParseIntFromUInt32Decimal(N: Int) {
|
||||
}
|
||||
|
||||
@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)!
|
||||
@@ -507,9 +507,9 @@ public func run_ParseIntFromUInt32Binary(N: Int) {
|
||||
}
|
||||
|
||||
@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)!
|
||||
@@ -519,9 +519,9 @@ public func run_ParseIntFromUInt32Hex(N: Int) {
|
||||
}
|
||||
|
||||
@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)!
|
||||
@@ -532,9 +532,9 @@ public func run_ParseIntFromUInt32UncommonRadix(N: Int) {
|
||||
|
||||
// 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)!
|
||||
@@ -544,9 +544,9 @@ public func run_ParseIntFromUInt64Decimal(N: Int) {
|
||||
}
|
||||
|
||||
@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)!
|
||||
@@ -556,9 +556,9 @@ public func run_ParseIntFromUInt64Binary(N: Int) {
|
||||
}
|
||||
|
||||
@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)!
|
||||
@@ -568,9 +568,9 @@ public func run_ParseIntFromUInt64Hex(N: Int) {
|
||||
}
|
||||
|
||||
@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)!
|
||||
|
||||
@@ -54,14 +54,14 @@ 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
|
||||
|
||||
@@ -31,8 +31,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, &+)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,9 +19,9 @@ public let Join = BenchmarkInfo(
|
||||
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: "")
|
||||
|
||||
@@ -35,10 +35,10 @@ 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
|
||||
}
|
||||
@@ -48,10 +48,10 @@ public func run_LazilyFilteredRange(_ N: Int) {
|
||||
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
|
||||
}
|
||||
@@ -61,9 +61,9 @@ public func run_LazilyFilteredArrays(_ N: Int) {
|
||||
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
|
||||
|
||||
@@ -38,11 +38,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 {
|
||||
|
||||
@@ -12,11 +12,11 @@ public let LuhnAlgoEager = BenchmarkInfo(
|
||||
)
|
||||
|
||||
@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 {
|
||||
|
||||
@@ -12,11 +12,11 @@ public let LuhnAlgoLazy = BenchmarkInfo(
|
||||
)
|
||||
|
||||
@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 {
|
||||
|
||||
@@ -71,11 +71,11 @@ 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, &+)
|
||||
}
|
||||
@@ -83,11 +83,11 @@ public func run_MapReduce(_ N: Int) {
|
||||
}
|
||||
|
||||
@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, &+)
|
||||
}
|
||||
@@ -95,11 +95,11 @@ public func run_MapReduceAnyCollection(_ N: Int) {
|
||||
}
|
||||
|
||||
@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, &+)
|
||||
}
|
||||
@@ -107,11 +107,11 @@ public func run_MapReduceAnyCollectionShort(_ N: Int) {
|
||||
}
|
||||
|
||||
@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, &+)
|
||||
}
|
||||
@@ -119,11 +119,11 @@ public func run_MapReduceShort(_ N: Int) {
|
||||
}
|
||||
|
||||
@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, &+)
|
||||
}
|
||||
@@ -131,11 +131,11 @@ public func run_MapReduceSequence(_ N: Int) {
|
||||
}
|
||||
|
||||
@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, &+)
|
||||
}
|
||||
@@ -143,11 +143,11 @@ public func run_MapReduceLazySequence(_ N: Int) {
|
||||
}
|
||||
|
||||
@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, &+)
|
||||
}
|
||||
@@ -155,11 +155,11 @@ public func run_MapReduceLazyCollection(_ N: Int) {
|
||||
}
|
||||
|
||||
@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, &+)
|
||||
}
|
||||
@@ -167,34 +167,34 @@ public func run_MapReduceLazyCollectionShort(_ N: Int) {
|
||||
}
|
||||
|
||||
@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, &+)
|
||||
}
|
||||
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, &+)
|
||||
}
|
||||
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, &+)
|
||||
}
|
||||
@@ -203,12 +203,12 @@ public func run_MapReduceNSDecimalNumber(_ N: Int) {
|
||||
}
|
||||
|
||||
@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, &+)
|
||||
}
|
||||
@@ -218,11 +218,11 @@ public func run_MapReduceNSDecimalNumberShort(_ N: Int) {
|
||||
|
||||
|
||||
@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, &+)
|
||||
}
|
||||
@@ -230,11 +230,11 @@ public func run_MapReduceClass(_ N: Int) {
|
||||
}
|
||||
|
||||
@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, &+)
|
||||
}
|
||||
|
||||
@@ -25,9 +25,9 @@ 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)
|
||||
}
|
||||
|
||||
@@ -37,7 +37,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,7 +50,7 @@ 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)
|
||||
}
|
||||
@@ -64,11 +64,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))
|
||||
|
||||
@@ -37,8 +37,8 @@ public func run_MonteCarloE(scale: Int) {
|
||||
let numEmptyIntervals = intervals.filter{!$0}.count
|
||||
// If there are no empty intervals, then obviously the random generator is
|
||||
// not 'random' enough.
|
||||
check(numEmptyIntervals != N)
|
||||
let e_estimate = Double(N)/Double(numEmptyIntervals)
|
||||
check(numEmptyIntervals != n)
|
||||
let e_estimate = Double(n)/Double(numEmptyIntervals)
|
||||
let e = 2.71828
|
||||
check(abs(e_estimate - e) < 0.2)
|
||||
}
|
||||
|
||||
@@ -23,15 +23,15 @@ public func run_MonteCarloPi(scale: Int) {
|
||||
|
||||
var pointsInside = 0
|
||||
let r = 10000
|
||||
let N = 4_000*scale
|
||||
for _ in 1...N {
|
||||
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
|
||||
check(abs(pi_estimate - pi) < 0.2)
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import TestsUtils
|
||||
// Mini benchmark implementing the gist of SwiftNIO's ChannelPipeline as
|
||||
// implemented by NIO 1 and NIO 2.[01]
|
||||
let t: [BenchmarkCategory] = [.runtime, .refcount, .cpubench]
|
||||
let N = 100
|
||||
let n = 100
|
||||
|
||||
public let NIOChannelPipeline = [
|
||||
BenchmarkInfo(
|
||||
|
||||
@@ -25,12 +25,12 @@ public let NSDictionaryCastToSwift = BenchmarkInfo(
|
||||
legacyFactor: 10)
|
||||
|
||||
@inline(never)
|
||||
public func run_NSDictionaryCastToSwift(_ N: Int) {
|
||||
public func run_NSDictionaryCastToSwift(_ n: Int) {
|
||||
#if _runtime(_ObjC)
|
||||
let NSDict = NSDictionary()
|
||||
let nsdict = NSDictionary()
|
||||
var swiftDict = [String: NSObject]()
|
||||
for _ in 1...1_000*N {
|
||||
swiftDict = NSDict as! [String: NSObject]
|
||||
for _ in 1...1_000*n {
|
||||
swiftDict = nsdict as! [String: NSObject]
|
||||
if !swiftDict.isEmpty {
|
||||
break
|
||||
}
|
||||
|
||||
@@ -39,8 +39,8 @@ func caller(_ x: P) throws {
|
||||
}
|
||||
|
||||
@inline(never)
|
||||
public func run_NSError(_ N: Int) {
|
||||
for _ in 1...N*1000 {
|
||||
public func run_NSError(_ n: Int) {
|
||||
for _ in 1...n*1000 {
|
||||
let k = K()
|
||||
let g = G()
|
||||
do {
|
||||
|
||||
@@ -105,44 +105,44 @@ public let NSStringConversion = [
|
||||
setUpFunction: { mutableTest = "Thë qüick bröwn föx jumps over the lazy dög" } )
|
||||
]
|
||||
|
||||
public func run_NSStringConversion(_ N: Int) {
|
||||
public func run_NSStringConversion(_ n: Int) {
|
||||
let test:NSString = NSString(cString: "test", encoding: String.Encoding.ascii.rawValue)!
|
||||
for _ in 1...N * 10000 {
|
||||
for _ in 1...n * 10000 {
|
||||
//Doesn't test accessing the String contents to avoid changing historical benchmark numbers
|
||||
blackHole(identity(test) as String)
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate func innerLoop(_ str: NSString, _ N: Int, _ scale: Int = 5000) {
|
||||
for _ in 1...N * scale {
|
||||
fileprivate func innerLoop(_ str: NSString, _ n: Int, _ scale: Int = 5000) {
|
||||
for _ in 1...n * scale {
|
||||
for char in (identity(str) as String).utf8 {
|
||||
blackHole(char)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public func run_NSStringConversion_nonASCII(_ N: Int) {
|
||||
innerLoop(test, N, 2500)
|
||||
public func run_NSStringConversion_nonASCII(_ n: Int) {
|
||||
innerLoop(test, n, 2500)
|
||||
}
|
||||
|
||||
public func run_NSMutableStringConversion(_ N: Int) {
|
||||
innerLoop(test, N)
|
||||
public func run_NSMutableStringConversion(_ n: Int) {
|
||||
innerLoop(test, n)
|
||||
}
|
||||
|
||||
public func run_NSStringConversion_medium(_ N: Int) {
|
||||
innerLoop(test, N, 1000)
|
||||
public func run_NSStringConversion_medium(_ n: Int) {
|
||||
innerLoop(test, n, 1000)
|
||||
}
|
||||
|
||||
public func run_NSStringConversion_long(_ N: Int) {
|
||||
innerLoop(test, N, 1000)
|
||||
public func run_NSStringConversion_long(_ n: Int) {
|
||||
innerLoop(test, n, 1000)
|
||||
}
|
||||
|
||||
public func run_NSStringConversion_longNonASCII(_ N: Int) {
|
||||
innerLoop(test, N, 300)
|
||||
public func run_NSStringConversion_longNonASCII(_ n: Int) {
|
||||
innerLoop(test, n, 300)
|
||||
}
|
||||
|
||||
fileprivate func innerMutableLoop(_ str: String, _ N: Int, _ scale: Int = 5000) {
|
||||
for _ in 1...N * scale {
|
||||
fileprivate func innerMutableLoop(_ str: String, _ n: Int, _ scale: Int = 5000) {
|
||||
for _ in 1...n * scale {
|
||||
let copy = (str as NSString).mutableCopy() as! NSMutableString
|
||||
for char in (identity(copy) as String).utf8 {
|
||||
blackHole(char)
|
||||
@@ -150,56 +150,56 @@ fileprivate func innerMutableLoop(_ str: String, _ N: Int, _ scale: Int = 5000)
|
||||
}
|
||||
}
|
||||
|
||||
public func run_NSStringConversion_nonASCIIMutable(_ N: Int) {
|
||||
innerMutableLoop(mutableTest, N, 500)
|
||||
public func run_NSStringConversion_nonASCIIMutable(_ n: Int) {
|
||||
innerMutableLoop(mutableTest, n, 500)
|
||||
}
|
||||
|
||||
public func run_NSStringConversion_mediumMutable(_ N: Int) {
|
||||
innerMutableLoop(mutableTest, N, 500)
|
||||
public func run_NSStringConversion_mediumMutable(_ n: Int) {
|
||||
innerMutableLoop(mutableTest, n, 500)
|
||||
}
|
||||
|
||||
public func run_NSStringConversion_longMutable(_ N: Int) {
|
||||
innerMutableLoop(mutableTest, N, 250)
|
||||
public func run_NSStringConversion_longMutable(_ n: Int) {
|
||||
innerMutableLoop(mutableTest, n, 250)
|
||||
}
|
||||
|
||||
public func run_NSStringConversion_longNonASCIIMutable(_ N: Int) {
|
||||
innerMutableLoop(mutableTest, N, 150)
|
||||
public func run_NSStringConversion_longNonASCIIMutable(_ n: Int) {
|
||||
innerMutableLoop(mutableTest, n, 150)
|
||||
}
|
||||
|
||||
fileprivate func innerRebridge(_ str: NSString, _ N: Int, _ scale: Int = 5000) {
|
||||
for _ in 1...N * scale {
|
||||
fileprivate func innerRebridge(_ str: NSString, _ n: Int, _ scale: Int = 5000) {
|
||||
for _ in 1...n * scale {
|
||||
let bridged = identity(str) as String
|
||||
blackHole(bridged)
|
||||
blackHole(bridged as NSString)
|
||||
}
|
||||
}
|
||||
|
||||
public func run_NSStringConversion_rebridge(_ N: Int) {
|
||||
innerRebridge(test, N, 2500)
|
||||
public func run_NSStringConversion_rebridge(_ n: Int) {
|
||||
innerRebridge(test, n, 2500)
|
||||
}
|
||||
|
||||
public func run_NSStringConversion_nonASCII_rebridge(_ N: Int) {
|
||||
innerRebridge(test, N, 2500)
|
||||
public func run_NSStringConversion_nonASCII_rebridge(_ n: Int) {
|
||||
innerRebridge(test, n, 2500)
|
||||
}
|
||||
|
||||
public func run_NSMutableStringConversion_rebridge(_ N: Int) {
|
||||
innerRebridge(test, N)
|
||||
public func run_NSMutableStringConversion_rebridge(_ n: Int) {
|
||||
innerRebridge(test, n)
|
||||
}
|
||||
|
||||
public func run_NSStringConversion_medium_rebridge(_ N: Int) {
|
||||
innerRebridge(test, N, 1000)
|
||||
public func run_NSStringConversion_medium_rebridge(_ n: Int) {
|
||||
innerRebridge(test, n, 1000)
|
||||
}
|
||||
|
||||
public func run_NSStringConversion_long_rebridge(_ N: Int) {
|
||||
innerRebridge(test, N, 1000)
|
||||
public func run_NSStringConversion_long_rebridge(_ n: Int) {
|
||||
innerRebridge(test, n, 1000)
|
||||
}
|
||||
|
||||
public func run_NSStringConversion_longNonASCII_rebridge(_ N: Int) {
|
||||
innerRebridge(test, N, 300)
|
||||
public func run_NSStringConversion_longNonASCII_rebridge(_ n: Int) {
|
||||
innerRebridge(test, n, 300)
|
||||
}
|
||||
|
||||
fileprivate func innerMutableRebridge(_ str: String, _ N: Int, _ scale: Int = 5000) {
|
||||
for _ in 1...N * scale {
|
||||
fileprivate func innerMutableRebridge(_ str: String, _ n: Int, _ scale: Int = 5000) {
|
||||
for _ in 1...n * scale {
|
||||
let copy = (str as NSString).mutableCopy() as! NSMutableString
|
||||
let bridged = identity(copy) as String
|
||||
blackHole(bridged)
|
||||
@@ -207,24 +207,24 @@ fileprivate func innerMutableRebridge(_ str: String, _ N: Int, _ scale: Int = 50
|
||||
}
|
||||
}
|
||||
|
||||
public func run_NSStringConversion_rebridgeMutable(_ N: Int) {
|
||||
innerMutableRebridge(mutableTest, N, 1000)
|
||||
public func run_NSStringConversion_rebridgeMutable(_ n: Int) {
|
||||
innerMutableRebridge(mutableTest, n, 1000)
|
||||
}
|
||||
|
||||
public func run_NSStringConversion_nonASCII_rebridgeMutable(_ N: Int) {
|
||||
innerMutableRebridge(mutableTest, N, 500)
|
||||
public func run_NSStringConversion_nonASCII_rebridgeMutable(_ n: Int) {
|
||||
innerMutableRebridge(mutableTest, n, 500)
|
||||
}
|
||||
|
||||
public func run_NSStringConversion_medium_rebridgeMutable(_ N: Int) {
|
||||
innerMutableRebridge(mutableTest, N, 500)
|
||||
public func run_NSStringConversion_medium_rebridgeMutable(_ n: Int) {
|
||||
innerMutableRebridge(mutableTest, n, 500)
|
||||
}
|
||||
|
||||
public func run_NSStringConversion_long_rebridgeMutable(_ N: Int) {
|
||||
innerMutableRebridge(mutableTest, N, 500)
|
||||
public func run_NSStringConversion_long_rebridgeMutable(_ n: Int) {
|
||||
innerMutableRebridge(mutableTest, n, 500)
|
||||
}
|
||||
|
||||
public func run_NSStringConversion_longNonASCII_rebridgeMutable(_ N: Int) {
|
||||
innerMutableRebridge(mutableTest, N, 300)
|
||||
public func run_NSStringConversion_longNonASCII_rebridgeMutable(_ n: Int) {
|
||||
innerMutableRebridge(mutableTest, n, 300)
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -12,12 +12,12 @@ public let NibbleSort = BenchmarkInfo(
|
||||
)
|
||||
|
||||
@inline(never)
|
||||
public func run_NibbleSort(_ N: Int) {
|
||||
public func run_NibbleSort(_ n: Int) {
|
||||
let vRef: UInt64 = 0xfeedbba000000000
|
||||
let v: UInt64 = 0xbadbeef
|
||||
var c = NibbleCollection(v)
|
||||
|
||||
for _ in 1...1_000*N {
|
||||
for _ in 1...1_000*n {
|
||||
c.val = v
|
||||
c.sort()
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user