Skip to content
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

[Benchmarks] Add Collection Equality Benchmarks #351

Merged
Merged
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions Benchmarks/Sources/Benchmarks/DequeBenchmarks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ extension Benchmark {
}

self.add(
title: "Deque<Int> equality different instance",
title: "Deque<Int> equality, unique",
input: Int.self
) { size in
let left = Deque(0 ..< size)
Expand All @@ -525,7 +525,7 @@ extension Benchmark {
}

self.add(
title: "Deque<Int> equality same instance",
title: "Deque<Int> equality, shared",
input: Int.self
) { size in
let left = Deque(0 ..< size)
Expand All @@ -536,5 +536,6 @@ extension Benchmark {
}
}
}

}
}
30 changes: 29 additions & 1 deletion Benchmarks/Sources/Benchmarks/DictionaryBenchmarks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,34 @@ extension Benchmark {
blackHole(d)
}
}


self.add(
title: "Dictionary<Int, Int> equality, unique",
input: [Int].self
) { input in
let keysAndValues = input.map { ($0, 2 * $0) }
let left = Dictionary(uniqueKeysWithValues: keysAndValues)
let right = Dictionary(uniqueKeysWithValues: keysAndValues)
return { timer in
timer.measure {
precondition(left == right)
}
}
}

self.add(
title: "Dictionary<Int, Int> equality, shared",
input: [Int].self
) { input in
let keysAndValues = input.map { ($0, 2 * $0) }
let left = Dictionary(uniqueKeysWithValues: keysAndValues)
let right = left
return { timer in
timer.measure {
precondition(left == right)
}
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ extension Benchmark {
}

self.add(
title: "OrderedDictionary<Int, Int> equality different instance",
title: "OrderedDictionary<Int, Int> equality, unique",
input: [Int].self
) { input in
let keysAndValues = input.map { ($0, 2 * $0) }
Expand All @@ -555,7 +555,7 @@ extension Benchmark {
}

self.add(
title: "OrderedDictionary<Int, Int> equality same instance",
title: "OrderedDictionary<Int, Int> equality, shared",
input: [Int].self
) { input in
let keysAndValues = input.map { ($0, 2 * $0) }
Expand All @@ -569,7 +569,7 @@ extension Benchmark {
}

self.add(
title: "OrderedDictionary<Int, Int>.Values equality different instance",
title: "OrderedDictionary<Int, Int>.Values equality, unique",
input: [Int].self
) { input in
let keysAndValues = input.map { ($0, 2 * $0) }
Expand All @@ -583,7 +583,7 @@ extension Benchmark {
}

self.add(
title: "OrderedDictionary<Int, Int>.Values equality same instance",
title: "OrderedDictionary<Int, Int>.Values equality, shared",
input: [Int].self
) { input in
let keysAndValues = input.map { ($0, 2 * $0) }
Expand All @@ -595,5 +595,6 @@ extension Benchmark {
}
}
}

}
}
8 changes: 4 additions & 4 deletions Benchmarks/Sources/Benchmarks/OrderedSetBenchmarks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ extension Benchmark {
}

self.add(
title: "OrderedSet<Int> equality different instance",
title: "OrderedSet<Int> equality, unique",
input: Int.self
) { size in
return { timer in
Expand All @@ -570,7 +570,7 @@ extension Benchmark {
}

self.add(
title: "OrderedSet<Int> equality same instance",
title: "OrderedSet<Int> equality, shared",
input: Int.self
) { size in
return { timer in
Expand All @@ -583,7 +583,7 @@ extension Benchmark {
}

self.add(
title: "OrderedSet<Int>.SubSequence equality different instance",
title: "OrderedSet<Int>.SubSequence equality, unique",
input: Int.self
) { size in
return { timer in
Expand All @@ -596,7 +596,7 @@ extension Benchmark {
}

self.add(
title: "OrderedSet<Int>.SubSequence equality same instance",
title: "OrderedSet<Int>.SubSequence equality, shared",
input: Int.self
) { size in
return { timer in
Expand Down
27 changes: 27 additions & 0 deletions Benchmarks/Sources/Benchmarks/SetBenchmarks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -473,5 +473,32 @@ extension Benchmark {
}
}
}

self.add(
title: "Set<Int> equality, unique",
input: Int.self
) { size in
return { timer in
let left = Set(0 ..< size)
let right = Set(0 ..< size)
timer.measure {
precondition(left == right)
}
}
}

self.add(
title: "Set<Int> equality, shared",
input: Int.self
) { size in
return { timer in
let left = Set(0 ..< size)
let right = left
timer.measure {
precondition(left == right)
}
}
}

}
}
27 changes: 27 additions & 0 deletions Benchmarks/Sources/Benchmarks/ShareableSetBenchmarks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -446,5 +446,32 @@ extension Benchmark {
}
}
}

self.add(
title: "TreeSet<Int> equality, unique",
input: Int.self
) { size in
return { timer in
let left = TreeSet(0 ..< size)
let right = TreeSet(0 ..< size)
timer.measure {
precondition(left == right)
}
}
}

self.add(
title: "TreeSet<Int> equality, shared",
input: Int.self
) { size in
return { timer in
let left = TreeSet(0 ..< size)
let right = left
timer.measure {
precondition(left == right)
}
}
}

}
}