@@ -21,99 +21,99 @@ import NIOCore
2121private let eventLoop = MultiThreadedEventLoopGroup . singleton. next ( )
2222
2323let benchmarks = {
24- let defaultMetrics : [ BenchmarkMetric ] = [
25- . mallocCountTotal,
26- . contextSwitches,
27- . wallClock,
28- ]
24+ let defaultMetrics : [ BenchmarkMetric ] = [
25+ . mallocCountTotal,
26+ . contextSwitches,
27+ . wallClock,
28+ ]
2929
30- Benchmark (
31- " MTELG.immediateTasksThroughput " ,
32- configuration: Benchmark . Configuration (
33- metrics: defaultMetrics,
34- scalingFactor: . mega,
35- maxDuration: . seconds( 10_000_000 ) ,
36- maxIterations: 5
37- )
38- ) { benchmark in
39- func noOp( ) { }
40- for _ in benchmark. scaledIterations {
41- eventLoop. execute { noOp ( ) }
30+ Benchmark (
31+ " MTELG.immediateTasksThroughput " ,
32+ configuration: Benchmark . Configuration (
33+ metrics: defaultMetrics,
34+ scalingFactor: . mega,
35+ maxDuration: . seconds( 10_000_000 ) ,
36+ maxIterations: 5
37+ )
38+ ) { benchmark in
39+ func noOp( ) { }
40+ for _ in benchmark. scaledIterations {
41+ eventLoop. execute { noOp ( ) }
42+ }
4243 }
43- }
4444
45- Benchmark (
46- " MTELG.scheduleTask(in:_:) " ,
47- configuration: Benchmark . Configuration (
48- metrics: defaultMetrics,
49- scalingFactor: . mega,
50- maxDuration: . seconds( 10_000_000 ) ,
51- maxIterations: 5
52- )
53- ) { benchmark in
54- for _ in benchmark. scaledIterations {
55- eventLoop. scheduleTask ( in: . hours( 1 ) , { } )
45+ Benchmark (
46+ " MTELG.scheduleTask(in:_:) " ,
47+ configuration: Benchmark . Configuration (
48+ metrics: defaultMetrics,
49+ scalingFactor: . mega,
50+ maxDuration: . seconds( 10_000_000 ) ,
51+ maxIterations: 5
52+ )
53+ ) { benchmark in
54+ for _ in benchmark. scaledIterations {
55+ eventLoop. scheduleTask ( in: . hours( 1 ) , { } )
56+ }
5657 }
57- }
5858
59- Benchmark (
60- " MTELG.scheduleCallback(in:_:) " ,
61- configuration: Benchmark . Configuration (
62- metrics: defaultMetrics,
63- scalingFactor: . mega,
64- maxDuration: . seconds( 10_000_000 ) ,
65- maxIterations: 5
66- )
67- ) { benchmark in
68- final class Timer : NIOScheduledCallbackHandler {
69- func handleScheduledCallback( eventLoop: some EventLoop ) { }
70- }
71- let timer = Timer ( )
59+ Benchmark (
60+ " MTELG.scheduleCallback(in:_:) " ,
61+ configuration: Benchmark . Configuration (
62+ metrics: defaultMetrics,
63+ scalingFactor: . mega,
64+ maxDuration: . seconds( 10_000_000 ) ,
65+ maxIterations: 5
66+ )
67+ ) { benchmark in
68+ final class Timer : NIOScheduledCallbackHandler {
69+ func handleScheduledCallback( eventLoop: some EventLoop ) { }
70+ }
71+ let timer = Timer ( )
7272
73- benchmark. startMeasurement ( )
74- for _ in benchmark. scaledIterations {
75- let handle = try ! eventLoop. scheduleCallback ( in: . hours( 1 ) , handler: timer)
73+ benchmark. startMeasurement ( )
74+ for _ in benchmark. scaledIterations {
75+ let handle = try ! eventLoop. scheduleCallback ( in: . hours( 1 ) , handler: timer)
76+ }
7677 }
77- }
7878
79- Benchmark (
80- " Jump to EL and back using execute and unsafecontinuation " ,
81- configuration: . init(
82- metrics: defaultMetrics,
83- scalingFactor: . kilo
84- )
85- ) { benchmark in
86- for _ in benchmark. scaledIterations {
87- await withUnsafeContinuation { ( continuation: UnsafeContinuation < Void , Never > ) in
88- eventLoop. execute {
89- continuation. resume ( )
79+ Benchmark (
80+ " Jump to EL and back using execute and unsafecontinuation " ,
81+ configuration: . init(
82+ metrics: defaultMetrics,
83+ scalingFactor: . kilo
84+ )
85+ ) { benchmark in
86+ for _ in benchmark. scaledIterations {
87+ await withUnsafeContinuation { ( continuation: UnsafeContinuation < Void , Never > ) in
88+ eventLoop. execute {
89+ continuation. resume ( )
90+ }
91+ }
9092 }
91- }
9293 }
93- }
9494
95- final actor Foo {
96- nonisolated public let unownedExecutor : UnownedSerialExecutor
95+ final actor Foo {
96+ nonisolated public let unownedExecutor : UnownedSerialExecutor
9797
98- init ( eventLoop: any EventLoop ) {
99- self . unownedExecutor = eventLoop. executor. asUnownedSerialExecutor ( )
100- }
98+ init ( eventLoop: any EventLoop ) {
99+ self . unownedExecutor = eventLoop. executor. asUnownedSerialExecutor ( )
100+ }
101101
102- func foo( ) {
103- blackHole ( Void ( ) )
102+ func foo( ) {
103+ blackHole ( Void ( ) )
104+ }
104105 }
105- }
106106
107- Benchmark (
108- " Jump to EL and back using actor with EL executor " ,
109- configuration: . init(
110- metrics: defaultMetrics,
111- scalingFactor: . kilo
112- )
113- ) { benchmark in
114- let actor = Foo ( eventLoop: eventLoop)
115- for _ in benchmark. scaledIterations {
116- await actor . foo ( )
107+ Benchmark (
108+ " Jump to EL and back using actor with EL executor " ,
109+ configuration: . init(
110+ metrics: defaultMetrics,
111+ scalingFactor: . kilo
112+ )
113+ ) { benchmark in
114+ let actor = Foo ( eventLoop: eventLoop)
115+ for _ in benchmark. scaledIterations {
116+ await actor . foo ( )
117+ }
117118 }
118- }
119119}
0 commit comments