-
-
Notifications
You must be signed in to change notification settings - Fork 56
Add Benchmarks for ConsoleLogger #222
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 hidden or 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,17 @@ | ||
| name: benchmark | ||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| sha: | ||
| type: string | ||
| required: true | ||
| description: "The commit SHA to run the benchmarks against." | ||
| push: | ||
| branches: [main] | ||
|
|
||
| jobs: | ||
| benchmark: | ||
| uses: vapor/ci/.github/workflows/run-benchmark.yml@main | ||
| with: | ||
| sha: ${{ inputs.sha }} | ||
| secrets: inherit |
This file contains hidden or 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 @@ | ||
| ../.gitignore | ||
This file contains hidden or 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 @@ | ||
| ../.swift-format |
52 changes: 52 additions & 0 deletions
52
Benchmarks/ConsoleLoggerBenchmarks/ConsoleLoggerBenchmarks.swift
This file contains hidden or 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,52 @@ | ||
| import Benchmark | ||
| import ConsoleKit | ||
| import ConsoleLogger | ||
| import Logging | ||
|
|
||
| let benchmarks: @Sendable () -> Void = { | ||
| Benchmark.defaultConfiguration = .init( | ||
| metrics: [.peakMemoryResident, .mallocCountTotal], | ||
| thresholds: [ | ||
| .peakMemoryResident: .init( | ||
| // Tolerate up to 4% of difference compared to the threshold. | ||
| relative: [.p90: 4], | ||
| // Tolerate up to one million bytes of difference compared to the threshold. | ||
| absolute: [.p90: 1_100_000] | ||
| ), | ||
| .mallocCountTotal: .init( | ||
| // Tolerate up to 1% of difference compared to the threshold. | ||
| relative: [.p90: 1], | ||
| // Tolerate up to 2 malloc calls of difference compared to the threshold. | ||
| absolute: [.p90: 2] | ||
| ), | ||
| ] | ||
| ) | ||
|
|
||
| Benchmark( | ||
| "Logging", | ||
| configuration: .init( | ||
| setup: { | ||
| let console = TestConsole() | ||
| LoggingSystem.bootstrap( | ||
| { label, provider in | ||
| ConsoleLogger(label: label, console: console) | ||
| }, | ||
| metadataProvider: .init { | ||
| ["provided1": "from metadata provider", "provided2": "another metadata provider"] | ||
| } | ||
| ) | ||
| } | ||
| ) | ||
| ) { benchmark in | ||
| var logger = Logger(label: "codes.vapor.console") | ||
| logger.logLevel = .trace | ||
| logger[metadataKey: "value"] = "one" | ||
|
|
||
| for _ in benchmark.scaledIterations { | ||
| logger.info( | ||
| "Info", | ||
| metadata: ["from-log": "value", "also-from-log": "other"] | ||
| ) | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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,47 @@ | ||
| import ConsoleKit | ||
| import Synchronization | ||
|
|
||
| /// A test console that captures input and output for testing purposes. | ||
| /// | ||
| /// > Warning: This class is a duplicate of the one in the main package, | ||
| /// remember to update all when making changes. | ||
| final class TestConsole: Console { | ||
| let _testInputQueue: Mutex<[String]> = Mutex([]) | ||
|
|
||
| var testInputQueue: [String] { | ||
| get { self._testInputQueue.withLock { $0 } } | ||
| set { self._testInputQueue.withLock { $0 = newValue } } | ||
| } | ||
|
|
||
| let _testOutputQueue: Mutex<[String]> = Mutex([]) | ||
| var testOutputQueue: [String] { | ||
| get { self._testOutputQueue.withLock { $0 } } | ||
| set { self._testOutputQueue.withLock { $0 = newValue } } | ||
| } | ||
|
|
||
| let _userInfo: Mutex<[AnySendableHashable: any Sendable]> = Mutex([:]) | ||
| var userInfo: [AnySendableHashable: any Sendable] { | ||
| get { self._userInfo.withLock { $0 } } | ||
| set { self._userInfo.withLock { $0 = newValue } } | ||
| } | ||
|
|
||
| init() { | ||
| self.testInputQueue = [] | ||
| self.testOutputQueue = [] | ||
| self.userInfo = [:] | ||
| } | ||
|
|
||
| func input(isSecure: Bool) -> String { | ||
| return testInputQueue.popLast() ?? "" | ||
| } | ||
|
|
||
| func output(_ text: ConsoleText, newLine: Bool) { | ||
| testOutputQueue.insert(text.description + (newLine ? "\n" : ""), at: 0) | ||
| } | ||
|
|
||
| func report(error: String, newLine: Bool) {} | ||
|
|
||
| func clear(_ type: ConsoleClear) {} | ||
|
|
||
| var size: (width: Int, height: Int) { (width: 32, height: 0) } | ||
| } |
This file contains hidden or 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,42 @@ | ||
| // swift-tools-version:6.1 | ||
| import PackageDescription | ||
|
|
||
| let package = Package( | ||
| name: "benchmarks", | ||
| platforms: [ | ||
| .macOS(.v15) | ||
| ], | ||
| dependencies: [ | ||
| .package(path: "../"), | ||
| .package(url: "https://github.com/ordo-one/package-benchmark.git", from: "1.29.2"), | ||
| .package(url: "https://github.com/apple/swift-log.git", from: "1.6.3"), | ||
| ], | ||
| targets: [ | ||
| .executableTarget( | ||
| name: "ConsoleLoggerBenchmarks", | ||
| dependencies: [ | ||
| .product(name: "Benchmark", package: "package-benchmark"), | ||
| .product(name: "ConsoleLogger", package: "console-kit"), | ||
| .product(name: "ConsoleKit", package: "console-kit"), | ||
| .product(name: "Logging", package: "swift-log"), | ||
| ], | ||
| path: "ConsoleLoggerBenchmarks", | ||
| swiftSettings: swiftSettings, | ||
| plugins: [ | ||
| .plugin(name: "BenchmarkPlugin", package: "package-benchmark") | ||
| ] | ||
| ) | ||
| ] | ||
| ) | ||
|
|
||
| var swiftSettings: [SwiftSetting] { | ||
| [ | ||
| .enableUpcomingFeature("ExistentialAny"), | ||
| .enableUpcomingFeature("MemberImportVisibility"), | ||
| .enableUpcomingFeature("ExistentialAny"), | ||
| .enableUpcomingFeature("InternalImportsByDefault"), | ||
| .enableUpcomingFeature("MemberImportVisibility"), | ||
| .enableUpcomingFeature("InferIsolatedConformances"), | ||
| .enableUpcomingFeature("ImmutableWeakCaptures"), | ||
| ] | ||
| } |
4 changes: 4 additions & 0 deletions
4
Benchmarks/Thresholds/ConsoleLoggerBenchmarks.Logging.p90.json
This file contains hidden or 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,4 @@ | ||
| { | ||
| "mallocCountTotal" : 48, | ||
| "peakMemoryResident" : 13279231 | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.