Skip to content

Commit bf69971

Browse files
committed
[benchmark] DictionaryGroupOfObjects Legacy Factor
1 parent 003d601 commit bf69971

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

benchmark/single-source/DictionaryGroup.swift

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,24 @@
1313
import TestsUtils
1414

1515
public let DictionaryGroup = [
16-
BenchmarkInfo(name: "DictionaryGroup", runFunction: run_DictionaryGroup, tags: [.validation, .api, .Dictionary]),
17-
BenchmarkInfo(name: "DictionaryGroupOfObjects", runFunction: run_DictionaryGroupOfObjects, tags: [.validation, .api, .Dictionary],
16+
BenchmarkInfo(name: "DictionaryGroup",
17+
runFunction: run_DictionaryGroup,
18+
tags: [.validation, .api, .Dictionary]),
19+
BenchmarkInfo(name: "DictionaryGroupOfObjects",
20+
runFunction: run_DictionaryGroupOfObjects,
21+
tags: [.validation, .api, .Dictionary],
1822
setUpFunction: { blackHole(inputObjects) },
19-
tearDownFunction: { inputObjects = nil }),
23+
tearDownFunction: { inputObjects = nil },
24+
legacyFactor: 9
25+
),
2026
]
2127

22-
let count = 10_000
23-
let result = count / 10
24-
2528
@inline(never)
2629
public func run_DictionaryGroup(_ N: Int) {
2730
for _ in 1...N {
28-
let dict = Dictionary(grouping: 0..<count, by: { $0 % 10 })
31+
let dict = Dictionary(grouping: 0..<10_000, by: { $0 % 10 })
2932
CheckResults(dict.count == 10)
30-
CheckResults(dict[0]!.count == result)
33+
CheckResults(dict[0]!.count == 1_000)
3134
}
3235
}
3336

@@ -47,14 +50,14 @@ class Box<T : Hashable> : Hashable {
4750
}
4851
}
4952

50-
var inputObjects: [Box<Int>]! = (0..<count).map { Box($0) }
53+
var inputObjects: [Box<Int>]! = (0..<1_000).lazy.map { Box($0) }
5154

5255
@inline(never)
5356
public func run_DictionaryGroupOfObjects(_ N: Int) {
5457
let objects: [Box<Int>] = inputObjects
5558
for _ in 1...N {
5659
let dict = Dictionary(grouping: objects, by: { Box($0.value % 10) })
5760
CheckResults(dict.count == 10)
58-
CheckResults(dict[Box(0)]!.count == result)
61+
CheckResults(dict[Box(0)]!.count == 100)
5962
}
6063
}

0 commit comments

Comments
 (0)