From afcd915044e05ae72157e87ff34497a0b601784d Mon Sep 17 00:00:00 2001 From: Michael Steindorfer Date: Wed, 24 Aug 2022 17:49:17 +0200 Subject: [PATCH] [Capsule] Add persistent dictionary `index` benchmarks --- .../PersistentDictionaryBenchmarks.swift | 46 +++++++++---------- Benchmarks/Libraries/Capsule.json | 20 ++++++++ 2 files changed, 43 insertions(+), 23 deletions(-) diff --git a/Benchmarks/Benchmarks/PersistentDictionaryBenchmarks.swift b/Benchmarks/Benchmarks/PersistentDictionaryBenchmarks.swift index c4c334fa..d386f52b 100644 --- a/Benchmarks/Benchmarks/PersistentDictionaryBenchmarks.swift +++ b/Benchmarks/Benchmarks/PersistentDictionaryBenchmarks.swift @@ -276,29 +276,29 @@ extension Benchmark { } } -// self.add( -// title: "PersistentDictionary successful index(forKey:)", -// input: ([Int], [Int]).self -// ) { input, lookups in -// let d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) }) -// return { timer in -// for i in lookups { -// precondition(d.index(forKey: i) != nil) -// } -// } -// } -// -// self.add( -// title: "PersistentDictionary unsuccessful index(forKey:)", -// input: ([Int], [Int]).self -// ) { input, lookups in -// let d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) }) -// return { timer in -// for i in lookups { -// precondition(d.index(forKey: lookups.count + i) == nil) -// } -// } -// } + self.add( + title: "PersistentDictionary successful index(forKey:)", + input: ([Int], [Int]).self + ) { input, lookups in + let d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) }) + return { timer in + for i in lookups { + precondition(d.index(forKey: i) != nil) + } + } + } + + self.add( + title: "PersistentDictionary unsuccessful index(forKey:)", + input: ([Int], [Int]).self + ) { input, lookups in + let d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) }) + return { timer in + for i in lookups { + precondition(d.index(forKey: lookups.count + i) == nil) + } + } + } self.add( title: "PersistentDictionary updateValue(_:forKey:), existing", diff --git a/Benchmarks/Libraries/Capsule.json b/Benchmarks/Libraries/Capsule.json index 67326f1d..5548cbc4 100644 --- a/Benchmarks/Libraries/Capsule.json +++ b/Benchmarks/Libraries/Capsule.json @@ -30,6 +30,8 @@ "PersistentDictionary updateValue(_:forKey:), insert", "PersistentDictionary random removals (existing keys)", "PersistentDictionary random removals (missing keys)", + "PersistentDictionary successful index(forKey:)", + "PersistentDictionary unsuccessful index(forKey:)", ] } ] @@ -89,6 +91,24 @@ "OrderedDictionary subscript, remove existing", ] }, + { + "kind": "chart", + "title": "index(forKey:), successful index(forKey:)", + "tasks": [ + "PersistentDictionary successful index(forKey:)", + "Dictionary successful index(forKey:)", + "OrderedDictionary successful index(forKey:)", + ] + }, + { + "kind": "chart", + "title": "index(forKey:), unsuccessful index(forKey:)", + "tasks": [ + "PersistentDictionary unsuccessful index(forKey:)", + "Dictionary unsuccessful index(forKey:)", + "OrderedDictionary unsuccessful index(forKey:)", + ] + }, ] }, ]