-
-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Date decoding strategy, benchmarks and allow changing default BSON settings #83
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ba119c8
Add timestamp to date decoding strategy
surajthomask 79cf36b
Add helper function to mutate decoder timestamp decoding strategy
surajthomask 7635551
Set default date decoding strategy to relative to reference date
surajthomask d16f2a1
Add bson date decoding tests
surajthomask cac4baa
Add benchmarks, enable FastBSONDecoder as part of BSONDecoder. New ov…
Joannis 6dbde5e
Fix boolean to enum case conversion for `relativeToReferenceDate`
Joannis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally forgot about Benchmark!