diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/SortedCollections.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/SortedCollections.xcscheme
new file mode 100644
index 00000000..a660e589
--- /dev/null
+++ b/.swiftpm/xcode/xcshareddata/xcschemes/SortedCollections.xcscheme
@@ -0,0 +1,87 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/swift-collections-Package.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/swift-collections-Package.xcscheme
index bf3d7efa..a59aafe9 100644
--- a/.swiftpm/xcode/xcshareddata/xcschemes/swift-collections-Package.xcscheme
+++ b/.swiftpm/xcode/xcshareddata/xcschemes/swift-collections-Package.xcscheme
@@ -37,28 +37,14 @@
-
-
-
-
@@ -76,6 +62,20 @@
ReferencedContainer = "container:">
+
+
+
+
+ buildForRunning = "YES"
+ buildForProfiling = "YES"
+ buildForArchiving = "YES"
+ buildForAnalyzing = "YES">
-
-
-
-
diff --git a/Benchmarks/Benchmarks/CppBenchmarks.swift b/Benchmarks/Benchmarks/CppBenchmarks.swift
index 219283f0..1433313b 100644
--- a/Benchmarks/Benchmarks/CppBenchmarks.swift
+++ b/Benchmarks/Benchmarks/CppBenchmarks.swift
@@ -139,6 +139,26 @@ internal class CppPriorityQueue {
}
}
+internal class CppMap {
+ var ptr: UnsafeMutableRawPointer?
+
+ init(_ input: [Int]) {
+ self.ptr = input.withUnsafeBufferPointer { buffer in
+ cpp_map_create(buffer.baseAddress, buffer.count)
+ }
+ }
+
+ deinit {
+ destroy()
+ }
+
+ func destroy() {
+ if let ptr = ptr {
+ cpp_map_destroy(ptr)
+ }
+ ptr = nil
+ }
+}
extension Benchmark {
public mutating func addCppBenchmarks() {
@@ -706,5 +726,28 @@ extension Benchmark {
pq.destroy()
}
}
+
+ //--------------------------------------------------------------------------
+
+// self.addSimple(
+// title: "std::map insert",
+// input: [Int].self
+// ) { input in
+// input.withUnsafeBufferPointer { buffer in
+// cpp_map_insert_integers(buffer.baseAddress, buffer.count)
+// }
+// }
+
+ self.add(
+ title: "std::map successful find",
+ input: ([Int], [Int]).self
+ ) { input, lookups in
+ let map = CppMap(input)
+ return { timer in
+ lookups.withUnsafeBufferPointer { buffer in
+ cpp_map_lookups(map.ptr, buffer.baseAddress, buffer.count, true)
+ }
+ }
+ }
}
}
diff --git a/Benchmarks/Benchmarks/SortedDictionaryBenchmarks.swift b/Benchmarks/Benchmarks/SortedDictionaryBenchmarks.swift
new file mode 100644
index 00000000..8e6daa8d
--- /dev/null
+++ b/Benchmarks/Benchmarks/SortedDictionaryBenchmarks.swift
@@ -0,0 +1,89 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the Swift Collections open source project
+//
+// Copyright (c) 2021 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+//
+//===----------------------------------------------------------------------===//
+
+import CollectionsBenchmark
+
+extension Benchmark {
+ public mutating func addSortedDictionaryBenchmarks() {
+// self.add(
+// title: "SortedDictionary init(uniqueKeysWithValues:)",
+// input: [Int].self
+// ) { input in
+// let keysAndValues = input.lazy.map { (key: $0, value: 2 * $0) }
+//
+// return { timer in
+// blackHole(SortedDictionary(uniqueKeysWithValues: keysAndValues))
+// }
+// }
+//
+// self.add(
+// title: "SortedDictionary subscript, append",
+// input: [Int].self
+// ) { input in
+// let keysAndValues = input.lazy.map { (key: $0, value: 2 * $0) }
+// var sortedDictionary = SortedDictionary()
+//
+// return { timer in
+// for (key, value) in keysAndValues {
+// sortedDictionary[key] = value
+// }
+// blackHole(sortedDictionary)
+// }
+// }
+
+ self.add(
+ title: "SortedDictionary subscript, successful lookups",
+ input: [Int].self
+ ) { input in
+ let keysAndValues = input.lazy.map { (key: $0, value: 2 * $0) }
+ let sortedDictionary = SortedDictionary(uniqueKeysWithValues: keysAndValues)
+
+ return { timer in
+ for (key, value) in keysAndValues {
+ precondition(sortedDictionary[key] == value)
+ }
+ }
+ }
+
+// self.add(
+// title: "SortedDictionary._BTree firstValue",
+// input: [Int].self
+// ) { input in
+// let keysAndValues = input.lazy.map { (key: $0, value: 2 * $0) }
+// var tree = _BTree()
+//
+// for (key, value) in keysAndValues {
+// tree.insertOrUpdate((key, value))
+// }
+//
+// return { timer in
+// for (key, value) in keysAndValues {
+// precondition(tree.anyValue(for: key) != nil)
+// }
+// }
+// }
+
+// self.add(
+// title: "SortedDictionary._BTree insertOrUpdate(element:)",
+// input: [Int].self
+// ) { input in
+// let keysAndValues = input.lazy.map { (key: $0, value: 2 * $0) }
+//
+// return { timer in
+// var tree = _BTree()
+// for (key, value) in keysAndValues {
+// tree.insertOrUpdate((key, value))
+// }
+// blackHole(tree)
+// }
+// }
+ }
+}
diff --git a/Benchmarks/CppBenchmarks/include/MapBenchmarks.h b/Benchmarks/CppBenchmarks/include/MapBenchmarks.h
new file mode 100644
index 00000000..53157439
--- /dev/null
+++ b/Benchmarks/CppBenchmarks/include/MapBenchmarks.h
@@ -0,0 +1,39 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the Swift Collections open source project
+//
+// Copyright (c) 2021 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef CPPBENCHMARKS_MAP_BENCHMARKS_H
+#define CPPBENCHMARKS_MAP_BENCHMARKS_H
+
+#include
+#include
+#include
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/// Create a std::map, populating it with data from the supplied buffer.
+/// Returns an opaque pointer to the created instance.
+extern void *cpp_map_create(const intptr_t *start, size_t count);
+
+/// Destroys an ordered map previously returned by `cpp_map_create`.
+extern void cpp_map_destroy(void *ptr);
+
+extern void cpp_map_insert_integers(const intptr_t *start, size_t count);
+
+extern void cpp_map_lookups(void *ptr, const intptr_t *start, size_t count, bool expectMatch);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* CPPBENCHMARKS_MAP_BENCHMARKS_H */
diff --git a/Benchmarks/CppBenchmarks/include/module.modulemap b/Benchmarks/CppBenchmarks/include/module.modulemap
index 7fbcf933..900b0f1a 100644
--- a/Benchmarks/CppBenchmarks/include/module.modulemap
+++ b/Benchmarks/CppBenchmarks/include/module.modulemap
@@ -5,6 +5,7 @@ module CppBenchmarks {
header "DequeBenchmarks.h"
header "UnorderedSetBenchmarks.h"
header "UnorderedMapBenchmarks.h"
+ header "MapBenchmarks.h"
header "PriorityQueueBenchmarks.h"
export *
}
diff --git a/Benchmarks/CppBenchmarks/src/MapBenchmarks.cpp b/Benchmarks/CppBenchmarks/src/MapBenchmarks.cpp
new file mode 100644
index 00000000..8e8c061e
--- /dev/null
+++ b/Benchmarks/CppBenchmarks/src/MapBenchmarks.cpp
@@ -0,0 +1,61 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the Swift Collections open source project
+//
+// Copyright (c) 2021 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+//
+//===----------------------------------------------------------------------===//
+
+#include "MapBenchmarks.h"
+#include