diff --git a/Benchmarks/Package.swift b/Benchmarks/Package.swift index d7a7ec64..90fca0ae 100644 --- a/Benchmarks/Package.swift +++ b/Benchmarks/Package.swift @@ -14,6 +14,9 @@ import PackageDescription let package = Package( name: "swift-collections.Benchmarks", + products: [ + .executable(name: "benchmark", targets: ["benchmark"]), + ], dependencies: [ .package(name: "swift-collections", path: ".."), .package(url: "https://github.com/apple/swift-collections-benchmark", from: "0.0.1"), @@ -26,21 +29,19 @@ let package = Package( .product(name: "CollectionsBenchmark", package: "swift-collections-benchmark"), "CppBenchmarks", ], - path: "Benchmarks", resources: [ .copy("Library.json"), ] ), .target( - name: "CppBenchmarks", - path: "CppBenchmarks" + name: "CppBenchmarks" ), .target( name: "benchmark", dependencies: [ "Benchmarks", ], - path: "benchmark-tool" + path: "Sources/benchmark-tool" ), ], cxxLanguageStandard: .cxx1z diff --git a/Benchmarks/Benchmarks/ArrayBenchmarks.swift b/Benchmarks/Sources/Benchmarks/ArrayBenchmarks.swift similarity index 100% rename from Benchmarks/Benchmarks/ArrayBenchmarks.swift rename to Benchmarks/Sources/Benchmarks/ArrayBenchmarks.swift diff --git a/Benchmarks/Benchmarks/BitsetBenchmarks.swift b/Benchmarks/Sources/Benchmarks/BitsetBenchmarks.swift similarity index 100% rename from Benchmarks/Benchmarks/BitsetBenchmarks.swift rename to Benchmarks/Sources/Benchmarks/BitsetBenchmarks.swift diff --git a/Benchmarks/Benchmarks/Cpp/CppBenchmarks.swift b/Benchmarks/Sources/Benchmarks/Cpp/CppBenchmarks.swift similarity index 100% rename from Benchmarks/Benchmarks/Cpp/CppBenchmarks.swift rename to Benchmarks/Sources/Benchmarks/Cpp/CppBenchmarks.swift diff --git a/Benchmarks/Benchmarks/Cpp/CppDequeBenchmarks.swift b/Benchmarks/Sources/Benchmarks/Cpp/CppDequeBenchmarks.swift similarity index 100% rename from Benchmarks/Benchmarks/Cpp/CppDequeBenchmarks.swift rename to Benchmarks/Sources/Benchmarks/Cpp/CppDequeBenchmarks.swift diff --git a/Benchmarks/Benchmarks/Cpp/CppMapBenchmarks.swift b/Benchmarks/Sources/Benchmarks/Cpp/CppMapBenchmarks.swift similarity index 100% rename from Benchmarks/Benchmarks/Cpp/CppMapBenchmarks.swift rename to Benchmarks/Sources/Benchmarks/Cpp/CppMapBenchmarks.swift diff --git a/Benchmarks/Benchmarks/Cpp/CppPriorityQueueBenchmarks.swift b/Benchmarks/Sources/Benchmarks/Cpp/CppPriorityQueueBenchmarks.swift similarity index 100% rename from Benchmarks/Benchmarks/Cpp/CppPriorityQueueBenchmarks.swift rename to Benchmarks/Sources/Benchmarks/Cpp/CppPriorityQueueBenchmarks.swift diff --git a/Benchmarks/Benchmarks/Cpp/CppUnorderedMapBenchmarks.swift b/Benchmarks/Sources/Benchmarks/Cpp/CppUnorderedMapBenchmarks.swift similarity index 100% rename from Benchmarks/Benchmarks/Cpp/CppUnorderedMapBenchmarks.swift rename to Benchmarks/Sources/Benchmarks/Cpp/CppUnorderedMapBenchmarks.swift diff --git a/Benchmarks/Benchmarks/Cpp/CppUnorderedSetBenchmarks.swift b/Benchmarks/Sources/Benchmarks/Cpp/CppUnorderedSetBenchmarks.swift similarity index 100% rename from Benchmarks/Benchmarks/Cpp/CppUnorderedSetBenchmarks.swift rename to Benchmarks/Sources/Benchmarks/Cpp/CppUnorderedSetBenchmarks.swift diff --git a/Benchmarks/Benchmarks/Cpp/CppVectorBenchmarks.swift b/Benchmarks/Sources/Benchmarks/Cpp/CppVectorBenchmarks.swift similarity index 100% rename from Benchmarks/Benchmarks/Cpp/CppVectorBenchmarks.swift rename to Benchmarks/Sources/Benchmarks/Cpp/CppVectorBenchmarks.swift diff --git a/Benchmarks/Benchmarks/Cpp/CppVectorBoolBenchmarks.swift b/Benchmarks/Sources/Benchmarks/Cpp/CppVectorBoolBenchmarks.swift similarity index 100% rename from Benchmarks/Benchmarks/Cpp/CppVectorBoolBenchmarks.swift rename to Benchmarks/Sources/Benchmarks/Cpp/CppVectorBoolBenchmarks.swift diff --git a/Benchmarks/Sources/Benchmarks/CustomGenerators.swift b/Benchmarks/Sources/Benchmarks/CustomGenerators.swift new file mode 100644 index 00000000..1e5e3ac3 --- /dev/null +++ b/Benchmarks/Sources/Benchmarks/CustomGenerators.swift @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2022 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 + +class Box {} + +struct Large: Hashable { + let v0: Int + let v1: Int + let v2: Int + let v3: Int + let v4: Int + let v5: Int + let v6: Int + let v7: Int + let v8: Int + let v9: Int + + init(_ value: Int) { + self.v0 = value + self.v1 = value + self.v2 = value + self.v3 = value + self.v4 = value + self.v5 = value + self.v6 = value + self.v7 = value + self.v8 = value + self.v9 = value + } + + static func ==(left: Self, right: Self) -> Bool { + left.v0 == right.v0 + } + + func hash(into hasher: inout Hasher) { + hasher.combine(v0) + } +} + +extension Benchmark { + public mutating func registerCustomGenerators() { + self.registerInputGenerator(for: [String].self) { size in + (0 ..< size).map { String($0) }.shuffled() + } + + self.registerInputGenerator(for: ([String], [String]).self) { size in + let items = (0 ..< size).map { String($0) } + return (items.shuffled(), items.shuffled()) + } + + self.registerInputGenerator(for: [Large].self) { size in + (0 ..< size).map { Large($0) }.shuffled() + } + + self.registerInputGenerator(for: ([Large], [Large]).self) { size in + let items = (0 ..< size).map { Large($0) } + return (items.shuffled(), items.shuffled()) + } + } +} diff --git a/Benchmarks/Benchmarks/DequeBenchmarks.swift b/Benchmarks/Sources/Benchmarks/DequeBenchmarks.swift similarity index 100% rename from Benchmarks/Benchmarks/DequeBenchmarks.swift rename to Benchmarks/Sources/Benchmarks/DequeBenchmarks.swift diff --git a/Benchmarks/Benchmarks/DictionaryBenchmarks.swift b/Benchmarks/Sources/Benchmarks/DictionaryBenchmarks.swift similarity index 100% rename from Benchmarks/Benchmarks/DictionaryBenchmarks.swift rename to Benchmarks/Sources/Benchmarks/DictionaryBenchmarks.swift diff --git a/Benchmarks/Benchmarks/Foundation/CFBinaryHeapBenchmarks.swift b/Benchmarks/Sources/Benchmarks/Foundation/CFBinaryHeapBenchmarks.swift similarity index 100% rename from Benchmarks/Benchmarks/Foundation/CFBinaryHeapBenchmarks.swift rename to Benchmarks/Sources/Benchmarks/Foundation/CFBinaryHeapBenchmarks.swift diff --git a/Benchmarks/Benchmarks/Foundation/CFBitVectorBenchmarks.swift b/Benchmarks/Sources/Benchmarks/Foundation/CFBitVectorBenchmarks.swift similarity index 100% rename from Benchmarks/Benchmarks/Foundation/CFBitVectorBenchmarks.swift rename to Benchmarks/Sources/Benchmarks/Foundation/CFBitVectorBenchmarks.swift diff --git a/Benchmarks/Benchmarks/Foundation/FoundationBenchmarks.swift b/Benchmarks/Sources/Benchmarks/Foundation/FoundationBenchmarks.swift similarity index 100% rename from Benchmarks/Benchmarks/Foundation/FoundationBenchmarks.swift rename to Benchmarks/Sources/Benchmarks/Foundation/FoundationBenchmarks.swift diff --git a/Benchmarks/Benchmarks/HeapBenchmarks.swift b/Benchmarks/Sources/Benchmarks/HeapBenchmarks.swift similarity index 100% rename from Benchmarks/Benchmarks/HeapBenchmarks.swift rename to Benchmarks/Sources/Benchmarks/HeapBenchmarks.swift diff --git a/Benchmarks/Benchmarks/Kalimba.swift b/Benchmarks/Sources/Benchmarks/Kalimba.swift similarity index 100% rename from Benchmarks/Benchmarks/Kalimba.swift rename to Benchmarks/Sources/Benchmarks/Kalimba.swift diff --git a/Benchmarks/Benchmarks/Library.json b/Benchmarks/Sources/Benchmarks/Library.json similarity index 100% rename from Benchmarks/Benchmarks/Library.json rename to Benchmarks/Sources/Benchmarks/Library.json diff --git a/Benchmarks/Benchmarks/Library.swift b/Benchmarks/Sources/Benchmarks/Library.swift similarity index 100% rename from Benchmarks/Benchmarks/Library.swift rename to Benchmarks/Sources/Benchmarks/Library.swift diff --git a/Benchmarks/Benchmarks/OrderedDictionaryBenchmarks.swift b/Benchmarks/Sources/Benchmarks/OrderedDictionaryBenchmarks.swift similarity index 100% rename from Benchmarks/Benchmarks/OrderedDictionaryBenchmarks.swift rename to Benchmarks/Sources/Benchmarks/OrderedDictionaryBenchmarks.swift diff --git a/Benchmarks/Benchmarks/OrderedSetBenchmarks.swift b/Benchmarks/Sources/Benchmarks/OrderedSetBenchmarks.swift similarity index 100% rename from Benchmarks/Benchmarks/OrderedSetBenchmarks.swift rename to Benchmarks/Sources/Benchmarks/OrderedSetBenchmarks.swift diff --git a/Benchmarks/Benchmarks/PersistentDictionaryBenchmarks.swift b/Benchmarks/Sources/Benchmarks/PersistentDictionaryBenchmarks.swift similarity index 100% rename from Benchmarks/Benchmarks/PersistentDictionaryBenchmarks.swift rename to Benchmarks/Sources/Benchmarks/PersistentDictionaryBenchmarks.swift diff --git a/Benchmarks/Benchmarks/SetBenchmarks.swift b/Benchmarks/Sources/Benchmarks/SetBenchmarks.swift similarity index 100% rename from Benchmarks/Benchmarks/SetBenchmarks.swift rename to Benchmarks/Sources/Benchmarks/SetBenchmarks.swift diff --git a/Benchmarks/Benchmarks/SortedDictionaryBenchmarks.swift b/Benchmarks/Sources/Benchmarks/SortedDictionaryBenchmarks.swift similarity index 100% rename from Benchmarks/Benchmarks/SortedDictionaryBenchmarks.swift rename to Benchmarks/Sources/Benchmarks/SortedDictionaryBenchmarks.swift diff --git a/Benchmarks/Benchmarks/SortedSetBenchmarks.swift b/Benchmarks/Sources/Benchmarks/SortedSetBenchmarks.swift similarity index 100% rename from Benchmarks/Benchmarks/SortedSetBenchmarks.swift rename to Benchmarks/Sources/Benchmarks/SortedSetBenchmarks.swift diff --git a/Benchmarks/CppBenchmarks/include/DequeBenchmarks.h b/Benchmarks/Sources/CppBenchmarks/include/DequeBenchmarks.h similarity index 100% rename from Benchmarks/CppBenchmarks/include/DequeBenchmarks.h rename to Benchmarks/Sources/CppBenchmarks/include/DequeBenchmarks.h diff --git a/Benchmarks/CppBenchmarks/include/Hashing.h b/Benchmarks/Sources/CppBenchmarks/include/Hashing.h similarity index 100% rename from Benchmarks/CppBenchmarks/include/Hashing.h rename to Benchmarks/Sources/CppBenchmarks/include/Hashing.h diff --git a/Benchmarks/CppBenchmarks/include/MapBenchmarks.h b/Benchmarks/Sources/CppBenchmarks/include/MapBenchmarks.h similarity index 100% rename from Benchmarks/CppBenchmarks/include/MapBenchmarks.h rename to Benchmarks/Sources/CppBenchmarks/include/MapBenchmarks.h diff --git a/Benchmarks/CppBenchmarks/include/PriorityQueueBenchmarks.h b/Benchmarks/Sources/CppBenchmarks/include/PriorityQueueBenchmarks.h similarity index 100% rename from Benchmarks/CppBenchmarks/include/PriorityQueueBenchmarks.h rename to Benchmarks/Sources/CppBenchmarks/include/PriorityQueueBenchmarks.h diff --git a/Benchmarks/CppBenchmarks/include/UnorderedMapBenchmarks.h b/Benchmarks/Sources/CppBenchmarks/include/UnorderedMapBenchmarks.h similarity index 100% rename from Benchmarks/CppBenchmarks/include/UnorderedMapBenchmarks.h rename to Benchmarks/Sources/CppBenchmarks/include/UnorderedMapBenchmarks.h diff --git a/Benchmarks/CppBenchmarks/include/UnorderedSetBenchmarks.h b/Benchmarks/Sources/CppBenchmarks/include/UnorderedSetBenchmarks.h similarity index 100% rename from Benchmarks/CppBenchmarks/include/UnorderedSetBenchmarks.h rename to Benchmarks/Sources/CppBenchmarks/include/UnorderedSetBenchmarks.h diff --git a/Benchmarks/CppBenchmarks/include/Utils.h b/Benchmarks/Sources/CppBenchmarks/include/Utils.h similarity index 100% rename from Benchmarks/CppBenchmarks/include/Utils.h rename to Benchmarks/Sources/CppBenchmarks/include/Utils.h diff --git a/Benchmarks/CppBenchmarks/include/VectorBenchmarks.h b/Benchmarks/Sources/CppBenchmarks/include/VectorBenchmarks.h similarity index 100% rename from Benchmarks/CppBenchmarks/include/VectorBenchmarks.h rename to Benchmarks/Sources/CppBenchmarks/include/VectorBenchmarks.h diff --git a/Benchmarks/CppBenchmarks/include/VectorBoolBenchmarks.h b/Benchmarks/Sources/CppBenchmarks/include/VectorBoolBenchmarks.h similarity index 100% rename from Benchmarks/CppBenchmarks/include/VectorBoolBenchmarks.h rename to Benchmarks/Sources/CppBenchmarks/include/VectorBoolBenchmarks.h diff --git a/Benchmarks/CppBenchmarks/include/module.modulemap b/Benchmarks/Sources/CppBenchmarks/include/module.modulemap similarity index 100% rename from Benchmarks/CppBenchmarks/include/module.modulemap rename to Benchmarks/Sources/CppBenchmarks/include/module.modulemap diff --git a/Benchmarks/CppBenchmarks/src/CustomHash.h b/Benchmarks/Sources/CppBenchmarks/src/CustomHash.h similarity index 100% rename from Benchmarks/CppBenchmarks/src/CustomHash.h rename to Benchmarks/Sources/CppBenchmarks/src/CustomHash.h diff --git a/Benchmarks/CppBenchmarks/src/DequeBenchmarks.cpp b/Benchmarks/Sources/CppBenchmarks/src/DequeBenchmarks.cpp similarity index 100% rename from Benchmarks/CppBenchmarks/src/DequeBenchmarks.cpp rename to Benchmarks/Sources/CppBenchmarks/src/DequeBenchmarks.cpp diff --git a/Benchmarks/CppBenchmarks/src/Hashing.cpp b/Benchmarks/Sources/CppBenchmarks/src/Hashing.cpp similarity index 100% rename from Benchmarks/CppBenchmarks/src/Hashing.cpp rename to Benchmarks/Sources/CppBenchmarks/src/Hashing.cpp diff --git a/Benchmarks/CppBenchmarks/src/MapBenchmarks.cpp b/Benchmarks/Sources/CppBenchmarks/src/MapBenchmarks.cpp similarity index 100% rename from Benchmarks/CppBenchmarks/src/MapBenchmarks.cpp rename to Benchmarks/Sources/CppBenchmarks/src/MapBenchmarks.cpp diff --git a/Benchmarks/CppBenchmarks/src/PriorityQueueBenchmarks.cpp b/Benchmarks/Sources/CppBenchmarks/src/PriorityQueueBenchmarks.cpp similarity index 100% rename from Benchmarks/CppBenchmarks/src/PriorityQueueBenchmarks.cpp rename to Benchmarks/Sources/CppBenchmarks/src/PriorityQueueBenchmarks.cpp diff --git a/Benchmarks/CppBenchmarks/src/UnorderedMapBenchmarks.cpp b/Benchmarks/Sources/CppBenchmarks/src/UnorderedMapBenchmarks.cpp similarity index 100% rename from Benchmarks/CppBenchmarks/src/UnorderedMapBenchmarks.cpp rename to Benchmarks/Sources/CppBenchmarks/src/UnorderedMapBenchmarks.cpp diff --git a/Benchmarks/CppBenchmarks/src/UnorderedSetBenchmarks.cpp b/Benchmarks/Sources/CppBenchmarks/src/UnorderedSetBenchmarks.cpp similarity index 100% rename from Benchmarks/CppBenchmarks/src/UnorderedSetBenchmarks.cpp rename to Benchmarks/Sources/CppBenchmarks/src/UnorderedSetBenchmarks.cpp diff --git a/Benchmarks/CppBenchmarks/src/Utils.cpp b/Benchmarks/Sources/CppBenchmarks/src/Utils.cpp similarity index 100% rename from Benchmarks/CppBenchmarks/src/Utils.cpp rename to Benchmarks/Sources/CppBenchmarks/src/Utils.cpp diff --git a/Benchmarks/CppBenchmarks/src/VectorBenchmarks.cpp b/Benchmarks/Sources/CppBenchmarks/src/VectorBenchmarks.cpp similarity index 100% rename from Benchmarks/CppBenchmarks/src/VectorBenchmarks.cpp rename to Benchmarks/Sources/CppBenchmarks/src/VectorBenchmarks.cpp diff --git a/Benchmarks/CppBenchmarks/src/VectorBoolBenchmarks.cpp b/Benchmarks/Sources/CppBenchmarks/src/VectorBoolBenchmarks.cpp similarity index 100% rename from Benchmarks/CppBenchmarks/src/VectorBoolBenchmarks.cpp rename to Benchmarks/Sources/CppBenchmarks/src/VectorBoolBenchmarks.cpp diff --git a/Benchmarks/benchmark-tool/main.swift b/Benchmarks/Sources/benchmark-tool/main.swift similarity index 100% rename from Benchmarks/benchmark-tool/main.swift rename to Benchmarks/Sources/benchmark-tool/main.swift diff --git a/Sources/PersistentCollections/Node/_HashTreeStatistics.swift b/Sources/PersistentCollections/Node/_HashTreeStatistics.swift new file mode 100644 index 00000000..011e65ba --- /dev/null +++ b/Sources/PersistentCollections/Node/_HashTreeStatistics.swift @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2022 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 Foundation