-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from orlandos-nl/date-decoding-strategy
Date decoding strategy, benchmarks and allow changing default BSON settings
- Loading branch information
Showing
10 changed files
with
557 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import BSON | ||
import Benchmark | ||
|
||
func bsonDecoderBenchmarks() { | ||
let smallDocument: Document = [ | ||
"string": "Hello, world!", | ||
"int": 42, | ||
"double": 3.14159, | ||
"bool": true, | ||
"array": [1, 2, 3, 4, 5], | ||
"document": ["key": "value"], | ||
] | ||
|
||
struct SmallType: Codable { | ||
let string: String | ||
let int: Int | ||
let double: Double | ||
let bool: Bool | ||
let array: [Int] | ||
let document: [String: String] | ||
} | ||
|
||
Benchmark("BSONDecoder:fastPath:small") { _ in | ||
blackHole( | ||
try BSONDecoder(settings: .fastPath) | ||
.decode(SmallType.self, from: smallDocument) | ||
) | ||
} | ||
|
||
Benchmark("BSONDecoder:adaptive:small") { _ in | ||
blackHole( | ||
try BSONDecoder(settings: .adaptive) | ||
.decode(SmallType.self, from: smallDocument) | ||
) | ||
} | ||
|
||
let largeDocument: Document = [ | ||
"string": "Hello, world!", | ||
"int": 42, | ||
"double": 3.14159, | ||
"bool": true, | ||
"array": [1, 2, 3, 4, 5], | ||
"document": ["key": "value"], | ||
"nested": [ | ||
"string": "Hello, world!", | ||
"int": 42, | ||
"double": 3.14159, | ||
"bool": true, | ||
"array": [1, 2, 3, 4, 5], | ||
"document": ["key": "value"], | ||
] as Document, | ||
] | ||
|
||
struct LargeType: Codable { | ||
let string: String | ||
let int: Int | ||
let double: Double | ||
let bool: Bool | ||
let array: [Int] | ||
let document: [String: String] | ||
let nested: SmallType | ||
} | ||
|
||
Benchmark("BSONDecoder:fastPath:large") { _ in | ||
blackHole( | ||
try BSONDecoder(settings: .fastPath) | ||
.decode(LargeType.self, from: largeDocument) | ||
) | ||
} | ||
|
||
Benchmark("BSONDecoder:adaptive:large") { _ in | ||
blackHole( | ||
try BSONDecoder(settings: .adaptive) | ||
.decode(LargeType.self, from: largeDocument) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import Benchmark | ||
|
||
let benchmarks = { | ||
Benchmark.defaultConfiguration = .init( | ||
metrics: [ | ||
.cpuTotal, | ||
.throughput, | ||
.mallocCountTotal, | ||
], | ||
warmupIterations: 10 | ||
) | ||
bsonDecoderBenchmarks() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// swift-tools-version: 5.9 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "Benchmarks", | ||
platforms: [.macOS(.v14)], | ||
dependencies: [ | ||
.package(url: "https://github.com/ordo-one/package-benchmark.git", .upToNextMajor(from: "1.0.0")), | ||
.package(path: "../"), | ||
], | ||
targets: [ | ||
// BSON benchmarks | ||
.executableTarget( | ||
name: "BSONBenchmarks", | ||
dependencies: [ | ||
.product(name: "Benchmark", package: "package-benchmark"), | ||
.product(name: "BSON", package: "BSON"), | ||
], | ||
path: "Benchmarks/BSON", | ||
plugins: [ | ||
.plugin(name: "BenchmarkPlugin", package: "package-benchmark"), | ||
] | ||
), | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.