@@ -22,6 +22,7 @@ import Valkey
2222@available ( valkeySwift 1 . 0 , * )
2323func connectionBenchmarks( ) {
2424 makeConnectionGETBenchmark ( )
25+ makeConnectionPipelineBenchmark ( )
2526}
2627
2728@available ( valkeySwift 1 . 0 , * )
@@ -51,3 +52,36 @@ func makeConnectionGETBenchmark() -> Benchmark? {
5152 try await serverMutex. withLock { $0 } ? . close ( ) . get ( )
5253 }
5354}
55+
56+ @available ( valkeySwift 1 . 0 , * )
57+ @discardableResult
58+ func makeConnectionPipelineBenchmark( ) -> Benchmark ? {
59+ let serverMutex = Mutex < ( any Channel ) ? > ( nil )
60+
61+ return Benchmark ( " Connection: Pipeline benchmark " , configuration: . init( metrics: defaultMetrics, scalingFactor: . kilo) ) { benchmark in
62+ let port = serverMutex. withLock { $0 } !. localAddress!. port!
63+ let logger = Logger ( label: " test " )
64+ try await ValkeyConnection . withConnection (
65+ address: . hostname( " 127.0.0.1 " , port: port) ,
66+ configuration: . init( ) ,
67+ logger: logger
68+ ) { connection in
69+ benchmark. startMeasurement ( )
70+ for _ in benchmark. scaledIterations {
71+ let foo = await connection. execute (
72+ GET ( " foo " ) ,
73+ GET ( " foo " ) ,
74+ GET ( " foo " )
75+ )
76+ let result = try foo. 2 . get ( ) . map { String ( buffer: $0) }
77+ precondition ( result == " Bar " )
78+ }
79+ benchmark. stopMeasurement ( )
80+ }
81+ } setup: {
82+ let server = try await makeLocalServer ( )
83+ serverMutex. withLock { $0 = server }
84+ } teardown: {
85+ try await serverMutex. withLock { $0 } ? . close ( ) . get ( )
86+ }
87+ }
0 commit comments