Skip to content

Commit c37c6f4

Browse files
authored
Merge pull request #10306 from natecook1000/nc-grouping-test
[benchmark] Fix the Dictionary(group:by:) test
2 parents 34e2014 + ced26b8 commit c37c6f4

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

benchmark/single-source/DictionaryGroup.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@
1212

1313
import TestsUtils
1414

15+
let count = 10_000
16+
let result = count / 10
17+
1518
@inline(never)
1619
public func run_DictionaryGroup(_ N: Int) {
17-
let count = 100 * N
18-
let result = count / 10
20+
for _ in 1...N {
1921
let dict = Dictionary(grouping: 0..<count, by: { $0 % 10 })
2022
CheckResults(dict.count == 10)
2123
CheckResults(dict[0]!.count == result)
24+
}
2225
}
2326

2427
class Box<T : Hashable> : Hashable {
@@ -39,9 +42,10 @@ class Box<T : Hashable> : Hashable {
3942

4043
@inline(never)
4144
public func run_DictionaryGroupOfObjects(_ N: Int) {
42-
let count = 20 * N
43-
let result = count / 10
44-
let dict = Dictionary(grouping: (0..<count).map { Box($0) }, by: { Box($0.value % 10) })
45+
let objects = (0..<count).map { Box($0) }
46+
for _ in 1...N {
47+
let dict = Dictionary(grouping: objects, by: { Box($0.value % 10) })
4548
CheckResults(dict.count == 10)
4649
CheckResults(dict[Box(0)]!.count == result)
50+
}
4751
}

0 commit comments

Comments
 (0)