Skip to content

Commit 06dd8e6

Browse files
committed
---
yaml --- r: 319349 b: refs/heads/master-rebranch c: 29b7893 h: refs/heads/master i: 319347: 0fe8a02
1 parent eb4a583 commit 06dd8e6

File tree

4 files changed

+108
-1
lines changed

4 files changed

+108
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1457,4 +1457,4 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-02-a: ddd2b2976aa9bfde5f20fe37f6bd2
14571457
refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-03-a: 171cc166f2abeb5ca2a4003700a8a78a108bd300
14581458
refs/heads/benlangmuir-patch-1: baaebaf39d52f3bf36710d4fe40cf212e996b212
14591459
refs/heads/i-do-redeclare: 8c4e6d5de5c1e3f0a2cedccf319df713ea22c48e
1460-
refs/heads/master-rebranch: c4665d0b5035de591f9a6245da19b6dc2dbdbbe9
1460+
refs/heads/master-rebranch: 29b789391aada6c08f8065d20ff7294d96789e44

branches/master-rebranch/benchmark/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ set(SWIFT_BENCH_MODULES
108108
single-source/NSError
109109
single-source/NSStringConversion
110110
single-source/NibbleSort
111+
single-source/NIOChannelPipeline
111112
single-source/NopDeinit
112113
single-source/ObjectAllocation
113114
single-source/ObjectiveCBridging
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
//===--- NIOChannelPipeline.swift -----------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2019 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import TestsUtils
14+
15+
// Mini benchmark implementing the gist of SwiftNIO's ChannelPipeline as
16+
// implemented by NIO 1 and NIO 2.[01]
17+
let t: [BenchmarkCategory] = [.runtime, .refcount]
18+
let N = 100
19+
20+
public let NIOChannelPipeline = [
21+
BenchmarkInfo(
22+
name: "NIOChannelPipeline",
23+
runFunction: runBench,
24+
tags: t),
25+
]
26+
27+
public protocol EventHandler: class {
28+
func event(holder: Holder)
29+
}
30+
31+
extension EventHandler {
32+
public func event(holder: Holder) {
33+
holder.fireEvent()
34+
}
35+
}
36+
37+
public final class Pipeline {
38+
var head: Holder? = nil
39+
40+
public init() {}
41+
42+
public func addHandler(_ handler: EventHandler) {
43+
if self.head == nil {
44+
self.head = Holder(handler)
45+
return
46+
}
47+
48+
var node = self.head
49+
while node?.next != nil {
50+
node = node?.next
51+
}
52+
node?.next = Holder(handler)
53+
}
54+
55+
public func fireEvent() {
56+
self.head!.invokeEvent()
57+
}
58+
}
59+
60+
public final class Holder {
61+
var next: Holder?
62+
let node: EventHandler
63+
64+
init(_ node: EventHandler) {
65+
self.next = nil
66+
self.node = node
67+
}
68+
69+
func invokeEvent() {
70+
self.node.event(holder: self)
71+
}
72+
73+
@inline(never)
74+
public func fireEvent() {
75+
self.next?.invokeEvent()
76+
}
77+
}
78+
79+
public final class NoOpHandler: EventHandler {
80+
public init() {}
81+
}
82+
83+
public final class ConsumingHandler: EventHandler {
84+
var consumed = 0
85+
public init() {}
86+
public func event(holder: Holder) {
87+
self.consumed += 1
88+
}
89+
}
90+
91+
@inline(never)
92+
func runBench(iterations: Int) {
93+
let pipeline = Pipeline()
94+
for _ in 0..<5 {
95+
pipeline.addHandler(NoOpHandler())
96+
}
97+
pipeline.addHandler(ConsumingHandler())
98+
99+
for _ in 0 ..< iterations {
100+
for _ in 0 ..< 1000 {
101+
pipeline.fireEvent()
102+
}
103+
}
104+
}

branches/master-rebranch/benchmark/utils/main.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ import Memset
9393
import MonteCarloE
9494
import MonteCarloPi
9595
import NibbleSort
96+
import NIOChannelPipeline
9697
import NSDictionaryCastToSwift
9798
import NSError
9899
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
@@ -272,6 +273,7 @@ registerBenchmark(NSErrorTest)
272273
registerBenchmark(NSStringConversion)
273274
#endif
274275
registerBenchmark(NibbleSort)
276+
registerBenchmark(NIOChannelPipeline)
275277
registerBenchmark(NopDeinit)
276278
registerBenchmark(ObjectAllocation)
277279
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)

0 commit comments

Comments
 (0)