Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 44 additions & 5 deletions Benchmarks/Benchmarks/NIOPosixBenchmarks/Benchmarks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ private let eventLoop = MultiThreadedEventLoopGroup.singleton.next()

let benchmarks = {
let defaultMetrics: [BenchmarkMetric] = [
.mallocCountTotal
.mallocCountTotal,
.contextSwitches,
.wallClock,
]

Benchmark(
Expand All @@ -38,9 +40,6 @@ let benchmarks = {
)
}

// This benchmark is only available above 5.9 since our EL conformance
// to serial executor is also gated behind 5.9.
#if compiler(>=5.9)
Benchmark(
"TCPEchoAsyncChannel",
configuration: .init(
Expand All @@ -66,7 +65,6 @@ let benchmarks = {
eventLoop: eventLoop
)
}
#endif

Benchmark(
"MTELG.scheduleTask(in:_:)",
Expand Down Expand Up @@ -101,4 +99,45 @@ let benchmarks = {
let handle = try! eventLoop.scheduleCallback(in: .hours(1), handler: timer)
}
}

Benchmark(
"Jump to EL and back using execute and unsafecontinuation",
configuration: .init(
metrics: defaultMetrics,
scalingFactor: .kilo
)
) { benchmark in
for _ in benchmark.scaledIterations {
await withUnsafeContinuation { (continuation: UnsafeContinuation<Void, Never>) in
eventLoop.execute {
continuation.resume()
}
}
}
}

final actor Foo {
nonisolated public let unownedExecutor: UnownedSerialExecutor

init(eventLoop: any EventLoop) {
self.unownedExecutor = eventLoop.executor.asUnownedSerialExecutor()
}

func foo() {
blackHole(Void())
}
}

Benchmark(
"Jump to EL and back using actor with EL executor",
configuration: .init(
metrics: defaultMetrics,
scalingFactor: .kilo
)
) { benchmark in
let actor = Foo(eventLoop: eventLoop)
for _ in benchmark.scaledIterations {
await actor.foo()
}
}
}
2 changes: 1 addition & 1 deletion Benchmarks/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.7
// swift-tools-version:5.9

import PackageDescription

Expand Down
Loading