Skip to content

Commit d489ba2

Browse files
committed
[benchmark] check results only once in ArrayRemoveAll
1 parent 51c62ae commit d489ba2

File tree

1 file changed

+16
-25
lines changed

1 file changed

+16
-25
lines changed

benchmark/single-source/ArrayRemoveAll.swift

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ public let benchmarks = [
1818
)
1919
]
2020

21+
class Slow {
22+
public var num: Int
23+
24+
init(num: Int) {
25+
self.num = num
26+
}
27+
}
28+
2129
let size_Int = 1_000_000
2230
let size_Class = 100_000
2331

@@ -39,44 +47,27 @@ var inputArray_Class: [Slow]! = {
3947
return a
4048
}()
4149

42-
class Slow {
43-
public var num: Int
44-
45-
init(num: Int) {
46-
self.num = num
47-
}
48-
}
49-
50-
51-
@inline(never)
52-
func verifyCapacity<T>(_ new: [T], orig: [T]) -> Bool {
53-
return new.capacity == orig.capacity
54-
}
55-
5650
@inline(never)
5751
func removeAll<T>(_ arr: [T]) -> [T] {
5852
var copy = arr
5953
copy.removeAll(keepingCapacity: true)
6054
return copy
6155
}
6256

63-
@inline(never)
64-
func copyItem<T>(_ item: T) -> T {
65-
return item
66-
}
67-
6857
@inline(never)
6958
func run_ArrayRemoveAll_Class(_ n: Int) {
70-
for _ in 1...n {
71-
let copy = removeAll(inputArray_Class)
72-
check(verifyCapacity(copy, orig: inputArray_Class))
59+
var copy = removeAll(inputArray_Class);
60+
for _ in 1..<n {
61+
copy = removeAll(inputArray_Class)
7362
}
63+
check(copy.capacity == inputArray_Class.capacity)
7464
}
7565

7666
@inline(never)
7767
func run_ArrayRemoveAll_Int(_ n: Int) {
78-
for _ in 1...n {
79-
let copy = removeAll(inputArray_Int)
80-
check(verifyCapacity(copy, orig: inputArray_Int))
68+
var copy = removeAll(inputArray_Int);
69+
for _ in 1..<n {
70+
copy = removeAll(inputArray_Int)
8171
}
72+
check(copy.capacity == inputArray_Int.capacity)
8273
}

0 commit comments

Comments
 (0)