@@ -87,6 +87,57 @@ extension XCTestCase {
87
87
}
88
88
}
89
89
90
+ public func measureSequenceThroughput< S: AsyncSequence , Output> ( firstOutput: @autoclosure ( ) -> Output , secondOutput: @autoclosure ( ) -> Output , _ sequenceBuilder: ( InfiniteAsyncSequence < Output > , InfiniteAsyncSequence < Output > ) -> S ) async where S: Sendable {
91
+ let metric = _ThroughputMetric ( )
92
+ let sampleTime : Double = 0.1
93
+
94
+ measure ( metrics: [ metric] ) {
95
+ let firstInfSeq = InfiniteAsyncSequence ( value: firstOutput ( ) , duration: sampleTime)
96
+ let secondInfSeq = InfiniteAsyncSequence ( value: secondOutput ( ) , duration: sampleTime)
97
+ let seq = sequenceBuilder ( firstInfSeq, secondInfSeq)
98
+
99
+ let exp = self . expectation ( description: " Finished " )
100
+ let iterTask = Task < Int , Error > {
101
+ var eventCount = 0
102
+ for try await _ in seq {
103
+ eventCount += 1
104
+ }
105
+ metric. eventCount = eventCount
106
+ exp. fulfill ( )
107
+ return eventCount
108
+ }
109
+ usleep ( UInt32 ( sampleTime * Double( USEC_PER_SEC) ) )
110
+ iterTask. cancel ( )
111
+ self . wait ( for: [ exp] , timeout: sampleTime * 2 )
112
+ }
113
+ }
114
+
115
+ public func measureSequenceThroughput< S: AsyncSequence , Output> ( firstOutput: @autoclosure ( ) -> Output , secondOutput: @autoclosure ( ) -> Output , thirdOutput: @autoclosure ( ) -> Output , _ sequenceBuilder: ( InfiniteAsyncSequence < Output > , InfiniteAsyncSequence < Output > , InfiniteAsyncSequence < Output > ) -> S ) async where S: Sendable {
116
+ let metric = _ThroughputMetric ( )
117
+ let sampleTime : Double = 0.1
118
+
119
+ measure ( metrics: [ metric] ) {
120
+ let firstInfSeq = InfiniteAsyncSequence ( value: firstOutput ( ) , duration: sampleTime)
121
+ let secondInfSeq = InfiniteAsyncSequence ( value: secondOutput ( ) , duration: sampleTime)
122
+ let thirdInfSeq = InfiniteAsyncSequence ( value: thirdOutput ( ) , duration: sampleTime)
123
+ let seq = sequenceBuilder ( firstInfSeq, secondInfSeq, thirdInfSeq)
124
+
125
+ let exp = self . expectation ( description: " Finished " )
126
+ let iterTask = Task < Int , Error > {
127
+ var eventCount = 0
128
+ for try await _ in seq {
129
+ eventCount += 1
130
+ }
131
+ metric. eventCount = eventCount
132
+ exp. fulfill ( )
133
+ return eventCount
134
+ }
135
+ usleep ( UInt32 ( sampleTime * Double( USEC_PER_SEC) ) )
136
+ iterTask. cancel ( )
137
+ self . wait ( for: [ exp] , timeout: sampleTime * 2 )
138
+ }
139
+ }
140
+
90
141
public func measureSequenceThroughput< S: AsyncSequence , Source: AsyncSequence > ( source: Source , _ sequenceBuilder: ( Source ) -> S ) async where S: Sendable , Source: Sendable {
91
142
let metric = _ThroughputMetric ( )
92
143
let sampleTime : Double = 0.1
0 commit comments