From 92d07b3910c8135dec880b61b59dcde75ee85590 Mon Sep 17 00:00:00 2001 From: Michael Steindorfer Date: Thu, 9 Dec 2021 18:14:52 +0100 Subject: [PATCH] [Capsule] Add `[COW] subscript, remove existing` benchmark --- .../Benchmarks/DictionaryBenchmarks.swift | 19 +++++++++++++++++++ .../OrderedDictionaryBenchmarks.swift | 19 +++++++++++++++++++ .../PersistentDictionaryBenchmarks.swift | 19 +++++++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/Benchmarks/Benchmarks/DictionaryBenchmarks.swift b/Benchmarks/Benchmarks/DictionaryBenchmarks.swift index 5020a4ea..5256c505 100644 --- a/Benchmarks/Benchmarks/DictionaryBenchmarks.swift +++ b/Benchmarks/Benchmarks/DictionaryBenchmarks.swift @@ -194,6 +194,25 @@ extension Benchmark { } } + self.add( + title: "Dictionary [COW] subscript, remove existing", + input: ([Int], [Int]).self + ) { input, lookups in + return { timer in + let d = Dictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) }) + timer.measure { + for i in lookups { + var e = d + e[i] = nil + precondition(e.count == input.count - 1) + blackHole(e) + } + } + precondition(d.count == input.count) + blackHole(d) + } + } + self.add( title: "Dictionary subscript, remove missing", input: ([Int], [Int]).self diff --git a/Benchmarks/Benchmarks/OrderedDictionaryBenchmarks.swift b/Benchmarks/Benchmarks/OrderedDictionaryBenchmarks.swift index bb3dff8e..5aab2308 100644 --- a/Benchmarks/Benchmarks/OrderedDictionaryBenchmarks.swift +++ b/Benchmarks/Benchmarks/OrderedDictionaryBenchmarks.swift @@ -226,6 +226,25 @@ extension Benchmark { } } + self.add( + title: "OrderedDictionary [COW] subscript, remove existing", + input: ([Int], [Int]).self + ) { input, lookups in + return { timer in + let d = OrderedDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) }) + timer.measure { + for i in lookups { + var e = d + e[i] = nil + precondition(e.count == input.count - 1) + blackHole(e) + } + } + precondition(d.count == input.count) + blackHole(d) + } + } + self.add( title: "OrderedDictionary subscript, remove missing", input: ([Int], [Int]).self diff --git a/Benchmarks/Benchmarks/PersistentDictionaryBenchmarks.swift b/Benchmarks/Benchmarks/PersistentDictionaryBenchmarks.swift index 42448b19..c4c334fa 100644 --- a/Benchmarks/Benchmarks/PersistentDictionaryBenchmarks.swift +++ b/Benchmarks/Benchmarks/PersistentDictionaryBenchmarks.swift @@ -182,6 +182,25 @@ extension Benchmark { } } + self.add( + title: "PersistentDictionary [COW] subscript, remove existing", + input: ([Int], [Int]).self + ) { input, lookups in + return { timer in + let d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) }) + timer.measure { + for i in lookups { + var e = d + e[i] = nil + precondition(e.count == input.count - 1) + blackHole(e) + } + } + precondition(d.count == input.count) + blackHole(d) + } + } + self.add( title: "PersistentDictionary subscript, remove missing", input: ([Int], [Int]).self