Skip to content

Commit ba55436

Browse files
authored
Add create and drop benchmark (#183)
Signed-off-by: Adam Fowler <[email protected]>
1 parent 600eafa commit ba55436

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Benchmarks/ValkeyBenchmarks/ValkeyConnectionBenchmark.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,37 @@ import Valkey
2121

2222
@available(valkeySwift 1.0, *)
2323
func connectionBenchmarks() {
24+
makeConnectionCreateAndDropBenchmark()
2425
makeConnectionGETBenchmark()
2526
makeConnectionPipelineBenchmark()
2627
}
2728

29+
@available(valkeySwift 1.0, *)
30+
@discardableResult
31+
func makeConnectionCreateAndDropBenchmark() -> Benchmark? {
32+
let serverMutex = Mutex<(any Channel)?>(nil)
33+
34+
return Benchmark("Connection: Create and drop benchmark", configuration: .init(metrics: defaultMetrics, scalingFactor: .kilo)) { benchmark in
35+
let port = serverMutex.withLock { $0 }!.localAddress!.port!
36+
let logger = Logger(label: "test")
37+
benchmark.startMeasurement()
38+
for _ in benchmark.scaledIterations {
39+
try await ValkeyConnection.withConnection(
40+
address: .hostname("127.0.0.1", port: port),
41+
configuration: .init(),
42+
logger: logger
43+
) { _ in
44+
}
45+
}
46+
benchmark.stopMeasurement()
47+
} setup: {
48+
let server = try await makeLocalServer()
49+
serverMutex.withLock { $0 = server }
50+
} teardown: {
51+
try await serverMutex.withLock { $0 }?.close().get()
52+
}
53+
}
54+
2855
@available(valkeySwift 1.0, *)
2956
@discardableResult
3057
func makeConnectionGETBenchmark() -> Benchmark? {

0 commit comments

Comments
 (0)