Skip to content

Commit

Permalink
Merge pull request #351 from vanvoorden/vanvoorden/equality-benchmarks
Browse files Browse the repository at this point in the history
[Benchmarks] Add Collection Equality Benchmarks
  • Loading branch information
lorentey authored Feb 6, 2024
2 parents 31de276 + 3c9df19 commit 30ed8ac
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 11 deletions.
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)
}
}
}

}
}

0 comments on commit 30ed8ac

Please sign in to comment.