Skip to content

[benchmark] Fix the Dictionary(group:by:) test #10306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 17, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions benchmark/single-source/DictionaryGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@

import TestsUtils

let count = 10_000
let result = count / 10

@inline(never)
public func run_DictionaryGroup(_ N: Int) {
let count = 100 * N
let result = count / 10
for _ in 1...N {
let dict = Dictionary(grouping: 0..<count, by: { $0 % 10 })
CheckResults(dict.count == 10)
CheckResults(dict[0]!.count == result)
}
}

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

@inline(never)
public func run_DictionaryGroupOfObjects(_ N: Int) {
let count = 20 * N
let result = count / 10
let dict = Dictionary(grouping: (0..<count).map { Box($0) }, by: { Box($0.value % 10) })
let objects = (0..<count).map { Box($0) }
for _ in 1...N {
let dict = Dictionary(grouping: objects, by: { Box($0.value % 10) })
CheckResults(dict.count == 10)
CheckResults(dict[Box(0)]!.count == result)
}
}