diff --git a/Benchmarks/Benchmarks/NIOCoreBenchmarks/Benchmarks.swift b/Benchmarks/Benchmarks/NIOCoreBenchmarks/Benchmarks.swift new file mode 100644 index 0000000000..39fa33c7df --- /dev/null +++ b/Benchmarks/Benchmarks/NIOCoreBenchmarks/Benchmarks.swift @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the SwiftNIO open source project +// +// Copyright (c) 2024 Apple Inc. and the SwiftNIO project authors +// Licensed under Apache License v2.0 +// +// See LICENSE.txt for license information +// See CONTRIBUTORS.txt for the list of SwiftNIO project authors +// +// SPDX-License-Identifier: Apache-2.0 +// +//===----------------------------------------------------------------------===// + +import Benchmark +import NIOCore +import NIOEmbedded + +let benchmarks = { + let defaultMetrics: [BenchmarkMetric] = [ + .mallocCountTotal, + ] + + Benchmark( + "NIOAsyncChannel.init", + configuration: Benchmark.Configuration(metrics: defaultMetrics) + ) { benchmark in + // Elide the cost of the 'EmbeddedChannel'. It's only used for its pipeline. + var channels: [EmbeddedChannel] = [] + channels.reserveCapacity(benchmark.scaledIterations.count) + for _ in 0 ..< benchmark.scaledIterations.count { + channels.append(EmbeddedChannel()) + } + + benchmark.startMeasurement() + defer { + benchmark.stopMeasurement() + } + for channel in channels { + let asyncChanel = try NIOAsyncChannel(wrappingChannelSynchronously: channel) + blackHole(asyncChanel) + } + } +} diff --git a/Benchmarks/Package.swift b/Benchmarks/Package.swift index 889dabe3b2..507159a7b1 100644 --- a/Benchmarks/Package.swift +++ b/Benchmarks/Package.swift @@ -37,5 +37,17 @@ let package = Package( .plugin(name: "BenchmarkPlugin", package: "package-benchmark") ] ), + .executableTarget( + name: "NIOCoreBenchmarks", + dependencies: [ + .product(name: "Benchmark", package: "package-benchmark"), + .product(name: "NIOCore", package: "swift-nio"), + .product(name: "NIOEmbedded", package: "swift-nio"), + ], + path: "Benchmarks/NIOCoreBenchmarks", + plugins: [ + .plugin(name: "BenchmarkPlugin", package: "package-benchmark") + ] + ), ] ) diff --git a/Benchmarks/Thresholds/5.10/NIOCoreBenchmarks.NIOAsyncChannel.init.p90.json b/Benchmarks/Thresholds/5.10/NIOCoreBenchmarks.NIOAsyncChannel.init.p90.json new file mode 100644 index 0000000000..4a3c90c5f3 --- /dev/null +++ b/Benchmarks/Thresholds/5.10/NIOCoreBenchmarks.NIOAsyncChannel.init.p90.json @@ -0,0 +1,3 @@ +{ + "mallocCountTotal" : 12 +} diff --git a/Benchmarks/Thresholds/5.8/NIOCoreBenchmarks.NIOAsyncChannel.init.p90.json b/Benchmarks/Thresholds/5.8/NIOCoreBenchmarks.NIOAsyncChannel.init.p90.json new file mode 100644 index 0000000000..4a3c90c5f3 --- /dev/null +++ b/Benchmarks/Thresholds/5.8/NIOCoreBenchmarks.NIOAsyncChannel.init.p90.json @@ -0,0 +1,3 @@ +{ + "mallocCountTotal" : 12 +} diff --git a/Benchmarks/Thresholds/5.9/NIOCoreBenchmarks.NIOAsyncChannel.init.p90.json b/Benchmarks/Thresholds/5.9/NIOCoreBenchmarks.NIOAsyncChannel.init.p90.json new file mode 100644 index 0000000000..4a3c90c5f3 --- /dev/null +++ b/Benchmarks/Thresholds/5.9/NIOCoreBenchmarks.NIOAsyncChannel.init.p90.json @@ -0,0 +1,3 @@ +{ + "mallocCountTotal" : 12 +} diff --git a/Benchmarks/Thresholds/main/NIOCoreBenchmarks.NIOAsyncChannel.init.p90.json b/Benchmarks/Thresholds/main/NIOCoreBenchmarks.NIOAsyncChannel.init.p90.json new file mode 100644 index 0000000000..4a3c90c5f3 --- /dev/null +++ b/Benchmarks/Thresholds/main/NIOCoreBenchmarks.NIOAsyncChannel.init.p90.json @@ -0,0 +1,3 @@ +{ + "mallocCountTotal" : 12 +}