diff --git a/Benchmarks/Benchmarks/NIOCoreBenchmarks/Benchmarks.swift b/Benchmarks/Benchmarks/NIOCoreBenchmarks/Benchmarks.swift index 39fa33c7df..f289073ed2 100644 --- a/Benchmarks/Benchmarks/NIOCoreBenchmarks/Benchmarks.swift +++ b/Benchmarks/Benchmarks/NIOCoreBenchmarks/Benchmarks.swift @@ -41,4 +41,11 @@ let benchmarks = { blackHole(asyncChanel) } } + + Benchmark( + "NIOLoopBoundBox.value", + configuration: .init(metrics: defaultMetrics, scalingFactor: .kilo) + ) { benchmark in + runNIOLoopBoundBoxInPlaceMutation(benchmark: benchmark) + } } diff --git a/Benchmarks/Benchmarks/NIOCoreBenchmarks/NIOLoopBoundBox.swift b/Benchmarks/Benchmarks/NIOCoreBenchmarks/NIOLoopBoundBox.swift new file mode 100644 index 0000000000..714480ffa6 --- /dev/null +++ b/Benchmarks/Benchmarks/NIOCoreBenchmarks/NIOLoopBoundBox.swift @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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 NIOCore +import NIOEmbedded +import Benchmark + +func runNIOLoopBoundBoxInPlaceMutation(benchmark: Benchmark) { + let embeddedEventLoop = EmbeddedEventLoop() + let boundBox = NIOLoopBoundBox([Int](), eventLoop: embeddedEventLoop) + boundBox.value.reserveCapacity(1) + + benchmark.startMeasurement() + + for _ in benchmark.scaledIterations { + boundBox.value.removeAll(keepingCapacity: true) + boundBox.value.append(1) + } + + benchmark.stopMeasurement() + + precondition(boundBox.value.count == 1) + precondition(boundBox.value.reduce(0, +) == 1) +} diff --git a/Benchmarks/Thresholds/5.10/NIOCoreBenchmarks.NIOAsyncChannel.init.p90.json b/Benchmarks/Thresholds/5.10/NIOCoreBenchmarks.NIOAsyncChannel.init.p90.json index 2554cd2c39..4505ee4c1c 100644 --- a/Benchmarks/Thresholds/5.10/NIOCoreBenchmarks.NIOAsyncChannel.init.p90.json +++ b/Benchmarks/Thresholds/5.10/NIOCoreBenchmarks.NIOAsyncChannel.init.p90.json @@ -1,3 +1,3 @@ { "mallocCountTotal" : 10 -} +} \ No newline at end of file diff --git a/Benchmarks/Thresholds/5.10/NIOCoreBenchmarks.NIOLoopBoundBox.value.p90.json b/Benchmarks/Thresholds/5.10/NIOCoreBenchmarks.NIOLoopBoundBox.value.p90.json new file mode 100644 index 0000000000..9f9de44c30 --- /dev/null +++ b/Benchmarks/Thresholds/5.10/NIOCoreBenchmarks.NIOLoopBoundBox.value.p90.json @@ -0,0 +1,3 @@ +{ + "mallocCountTotal" : 0 +} \ No newline at end of file diff --git a/Benchmarks/Thresholds/5.10/NIOPosixBenchmarks.TCPEcho.p90.json b/Benchmarks/Thresholds/5.10/NIOPosixBenchmarks.TCPEcho.p90.json index c6a93680d0..fa70aea890 100644 --- a/Benchmarks/Thresholds/5.10/NIOPosixBenchmarks.TCPEcho.p90.json +++ b/Benchmarks/Thresholds/5.10/NIOPosixBenchmarks.TCPEcho.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 108 -} + "mallocCountTotal" : 90 +} \ No newline at end of file diff --git a/Benchmarks/Thresholds/5.10/NIOPosixBenchmarks.TCPEchoAsyncChannel.p90.json b/Benchmarks/Thresholds/5.10/NIOPosixBenchmarks.TCPEchoAsyncChannel.p90.json index 361ee44ab6..a9cae74898 100644 --- a/Benchmarks/Thresholds/5.10/NIOPosixBenchmarks.TCPEchoAsyncChannel.p90.json +++ b/Benchmarks/Thresholds/5.10/NIOPosixBenchmarks.TCPEchoAsyncChannel.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 165000 -} + "mallocCountTotal" : 164212 +} \ No newline at end of file diff --git a/Benchmarks/Thresholds/5.8/NIOCoreBenchmarks.NIOAsyncChannel.init.p90.json b/Benchmarks/Thresholds/5.8/NIOCoreBenchmarks.NIOAsyncChannel.init.p90.json index 2554cd2c39..4505ee4c1c 100644 --- a/Benchmarks/Thresholds/5.8/NIOCoreBenchmarks.NIOAsyncChannel.init.p90.json +++ b/Benchmarks/Thresholds/5.8/NIOCoreBenchmarks.NIOAsyncChannel.init.p90.json @@ -1,3 +1,3 @@ { "mallocCountTotal" : 10 -} +} \ No newline at end of file diff --git a/Benchmarks/Thresholds/5.8/NIOCoreBenchmarks.NIOLoopBoundBox.value.p90.json b/Benchmarks/Thresholds/5.8/NIOCoreBenchmarks.NIOLoopBoundBox.value.p90.json new file mode 100644 index 0000000000..9f9de44c30 --- /dev/null +++ b/Benchmarks/Thresholds/5.8/NIOCoreBenchmarks.NIOLoopBoundBox.value.p90.json @@ -0,0 +1,3 @@ +{ + "mallocCountTotal" : 0 +} \ No newline at end of file diff --git a/Benchmarks/Thresholds/5.8/NIOPosixBenchmarks.TCPEcho.p90.json b/Benchmarks/Thresholds/5.8/NIOPosixBenchmarks.TCPEcho.p90.json index 248bd96061..1859f424c5 100644 --- a/Benchmarks/Thresholds/5.8/NIOPosixBenchmarks.TCPEcho.p90.json +++ b/Benchmarks/Thresholds/5.8/NIOPosixBenchmarks.TCPEcho.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 110 -} + "mallocCountTotal" : 92 +} \ No newline at end of file diff --git a/Benchmarks/Thresholds/5.9/NIOCoreBenchmarks.NIOAsyncChannel.init.p90.json b/Benchmarks/Thresholds/5.9/NIOCoreBenchmarks.NIOAsyncChannel.init.p90.json index 2554cd2c39..4505ee4c1c 100644 --- a/Benchmarks/Thresholds/5.9/NIOCoreBenchmarks.NIOAsyncChannel.init.p90.json +++ b/Benchmarks/Thresholds/5.9/NIOCoreBenchmarks.NIOAsyncChannel.init.p90.json @@ -1,3 +1,3 @@ { "mallocCountTotal" : 10 -} +} \ No newline at end of file diff --git a/Benchmarks/Thresholds/5.9/NIOCoreBenchmarks.NIOLoopBoundBox.value.p90.json b/Benchmarks/Thresholds/5.9/NIOCoreBenchmarks.NIOLoopBoundBox.value.p90.json new file mode 100644 index 0000000000..9f9de44c30 --- /dev/null +++ b/Benchmarks/Thresholds/5.9/NIOCoreBenchmarks.NIOLoopBoundBox.value.p90.json @@ -0,0 +1,3 @@ +{ + "mallocCountTotal" : 0 +} \ No newline at end of file diff --git a/Benchmarks/Thresholds/5.9/NIOPosixBenchmarks.TCPEcho.p90.json b/Benchmarks/Thresholds/5.9/NIOPosixBenchmarks.TCPEcho.p90.json index 248bd96061..1859f424c5 100644 --- a/Benchmarks/Thresholds/5.9/NIOPosixBenchmarks.TCPEcho.p90.json +++ b/Benchmarks/Thresholds/5.9/NIOPosixBenchmarks.TCPEcho.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 110 -} + "mallocCountTotal" : 92 +} \ No newline at end of file diff --git a/Benchmarks/Thresholds/5.9/NIOPosixBenchmarks.TCPEchoAsyncChannel.p90.json b/Benchmarks/Thresholds/5.9/NIOPosixBenchmarks.TCPEchoAsyncChannel.p90.json index 2b218b490e..709428402c 100644 --- a/Benchmarks/Thresholds/5.9/NIOPosixBenchmarks.TCPEchoAsyncChannel.p90.json +++ b/Benchmarks/Thresholds/5.9/NIOPosixBenchmarks.TCPEchoAsyncChannel.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 164000 -} + "mallocCountTotal" : 164216 +} \ No newline at end of file diff --git a/Benchmarks/Thresholds/nightly-main/NIOCoreBenchmarks.NIOAsyncChannel.init.p90.json b/Benchmarks/Thresholds/nightly-main/NIOCoreBenchmarks.NIOAsyncChannel.init.p90.json index 2554cd2c39..4505ee4c1c 100644 --- a/Benchmarks/Thresholds/nightly-main/NIOCoreBenchmarks.NIOAsyncChannel.init.p90.json +++ b/Benchmarks/Thresholds/nightly-main/NIOCoreBenchmarks.NIOAsyncChannel.init.p90.json @@ -1,3 +1,3 @@ { "mallocCountTotal" : 10 -} +} \ No newline at end of file diff --git a/Benchmarks/Thresholds/nightly-main/NIOCoreBenchmarks.NIOLoopBoundBox.value.p90.json b/Benchmarks/Thresholds/nightly-main/NIOCoreBenchmarks.NIOLoopBoundBox.value.p90.json new file mode 100644 index 0000000000..9f9de44c30 --- /dev/null +++ b/Benchmarks/Thresholds/nightly-main/NIOCoreBenchmarks.NIOLoopBoundBox.value.p90.json @@ -0,0 +1,3 @@ +{ + "mallocCountTotal" : 0 +} \ No newline at end of file diff --git a/Benchmarks/Thresholds/nightly-main/NIOPosixBenchmarks.TCPEcho.p90.json b/Benchmarks/Thresholds/nightly-main/NIOPosixBenchmarks.TCPEcho.p90.json index c6a93680d0..fa70aea890 100644 --- a/Benchmarks/Thresholds/nightly-main/NIOPosixBenchmarks.TCPEcho.p90.json +++ b/Benchmarks/Thresholds/nightly-main/NIOPosixBenchmarks.TCPEcho.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 108 -} + "mallocCountTotal" : 90 +} \ No newline at end of file diff --git a/Benchmarks/Thresholds/nightly-main/NIOPosixBenchmarks.TCPEchoAsyncChannel.p90.json b/Benchmarks/Thresholds/nightly-main/NIOPosixBenchmarks.TCPEchoAsyncChannel.p90.json index 361ee44ab6..76abebdbb5 100644 --- a/Benchmarks/Thresholds/nightly-main/NIOPosixBenchmarks.TCPEchoAsyncChannel.p90.json +++ b/Benchmarks/Thresholds/nightly-main/NIOPosixBenchmarks.TCPEchoAsyncChannel.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 165000 -} + "mallocCountTotal" : 164210 +} \ No newline at end of file diff --git a/Benchmarks/Thresholds/nightly-next/NIOCoreBenchmarks.NIOAsyncChannel.init.p90.json b/Benchmarks/Thresholds/nightly-next/NIOCoreBenchmarks.NIOAsyncChannel.init.p90.json index 2554cd2c39..4505ee4c1c 100644 --- a/Benchmarks/Thresholds/nightly-next/NIOCoreBenchmarks.NIOAsyncChannel.init.p90.json +++ b/Benchmarks/Thresholds/nightly-next/NIOCoreBenchmarks.NIOAsyncChannel.init.p90.json @@ -1,3 +1,3 @@ { "mallocCountTotal" : 10 -} +} \ No newline at end of file diff --git a/Benchmarks/Thresholds/nightly-next/NIOCoreBenchmarks.NIOLoopBoundBox.value.p90.json b/Benchmarks/Thresholds/nightly-next/NIOCoreBenchmarks.NIOLoopBoundBox.value.p90.json new file mode 100644 index 0000000000..9f9de44c30 --- /dev/null +++ b/Benchmarks/Thresholds/nightly-next/NIOCoreBenchmarks.NIOLoopBoundBox.value.p90.json @@ -0,0 +1,3 @@ +{ + "mallocCountTotal" : 0 +} \ No newline at end of file diff --git a/Benchmarks/Thresholds/nightly-next/NIOPosixBenchmarks.TCPEcho.p90.json b/Benchmarks/Thresholds/nightly-next/NIOPosixBenchmarks.TCPEcho.p90.json index c6a93680d0..fa70aea890 100644 --- a/Benchmarks/Thresholds/nightly-next/NIOPosixBenchmarks.TCPEcho.p90.json +++ b/Benchmarks/Thresholds/nightly-next/NIOPosixBenchmarks.TCPEcho.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 108 -} + "mallocCountTotal" : 90 +} \ No newline at end of file diff --git a/Benchmarks/Thresholds/nightly-next/NIOPosixBenchmarks.TCPEchoAsyncChannel.p90.json b/Benchmarks/Thresholds/nightly-next/NIOPosixBenchmarks.TCPEchoAsyncChannel.p90.json index 361ee44ab6..4668dfe00d 100644 --- a/Benchmarks/Thresholds/nightly-next/NIOPosixBenchmarks.TCPEchoAsyncChannel.p90.json +++ b/Benchmarks/Thresholds/nightly-next/NIOPosixBenchmarks.TCPEchoAsyncChannel.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 165000 -} + "mallocCountTotal" : 164206 +} \ No newline at end of file