Skip to content

Commit

Permalink
Add benchmarks (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
lovetodream authored Jul 6, 2024
1 parent 4a2274a commit 84068c7
Show file tree
Hide file tree
Showing 5 changed files with 285 additions and 4 deletions.
10 changes: 10 additions & 0 deletions Benchmarks/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.DS_Store
/.build
/Packages
/*.xcodeproj
xcuserdata/
DerivedData/
.swiftpm/config/registries.json
.swiftpm/xcode/
.netrc
.vscode/settings.json
82 changes: 82 additions & 0 deletions Benchmarks/Benchmarks/OracleBench/OracleBenchmarks.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the OracleNIO open source project
//
// Copyright (c) 2024 Timo Zacherl and the OracleNIO project authors
// Licensed under Apache License v2.0
//
// See LICENSE for license information
// See CONTRIBUTORS.md for the list of OracleNIO project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

import Benchmark
import Foundation
import OracleNIO

private func env(_ name: String) -> String? {
getenv(name).flatMap { String(cString: $0) }
}

extension Benchmark {
@discardableResult
convenience init?(
name: String,
configuration: Benchmark.Configuration = Benchmark.defaultConfiguration,
write: @escaping @Sendable (Benchmark, OracleConnection) async throws -> Void
) {
let config = OracleConnection.Configuration(
host: env("ORA_HOSTNAME") ?? "192.168.1.24",
port: env("ORA_PORT").flatMap(Int.init) ?? 1521,
service: .serviceName(env("ORA_SERVICE_NAME") ?? "XEPDB1"),
username: env("ORA_USERNAME") ?? "my_user",
password: env("ORA_PASSWORD") ?? "my_passwor"
)
var connection: OracleConnection!
self.init(name, configuration: configuration) { benchmark in
for _ in benchmark.scaledIterations {
for _ in 0..<25 {
try await write(benchmark, connection)
}
}
} setup: {
connection = try await OracleConnection.connect(
configuration: config,
id: 1
)
} teardown: {
try await connection.close()
}
}
}

let benchmarks = {
Benchmark.defaultConfiguration = .init(
metrics: [
.cpuTotal,
.contextSwitches,
.throughput,
.mallocCountTotal,
],
warmupIterations: 10
)
Benchmark(
name: "SELECT:DUAL:1",
configuration: .init(warmupIterations: 10)
) { _, connection in
let stream = try await connection.execute("SELECT 'hello' FROM dual")
for try await _ in stream.decode(String.self) {} // consume stream
}

Benchmark(
name: "SELECT:DUAL:10_000",
configuration: .init(warmupIterations: 10)
) { _, connection in
let stream = try await connection.execute(
"SELECT to_number(column_value) AS id FROM xmltable ('1 to 10000')"
)
for try await _ in stream.decode(Int.self) {} // consume stream
}
}
168 changes: 168 additions & 0 deletions Benchmarks/Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
{
"originHash" : "bf919706c87a06ed1de06d4174a92e575d6393b41272bd8e776b44aedbb4dd15",
"pins" : [
{
"identity" : "hdrhistogram-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/HdrHistogram/hdrhistogram-swift",
"state" : {
"revision" : "a69fa24d7b70421870cafa86340ece900489e17e",
"version" : "0.1.2"
}
},
{
"identity" : "package-benchmark",
"kind" : "remoteSourceControl",
"location" : "https://github.com/ordo-one/package-benchmark.git",
"state" : {
"revision" : "6889229e21c6d9d0421a050e9e11c8f5eb5bc279",
"version" : "1.23.5"
}
},
{
"identity" : "package-jemalloc",
"kind" : "remoteSourceControl",
"location" : "https://github.com/ordo-one/package-jemalloc",
"state" : {
"revision" : "e8a5db026963f5bfeac842d9d3f2cc8cde323b49",
"version" : "1.0.0"
}
},
{
"identity" : "postgres-nio",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/postgres-nio.git",
"state" : {
"revision" : "5c268768890b062803a49f1358becc478f954265",
"version" : "1.21.5"
}
},
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser",
"state" : {
"revision" : "0fbc8848e389af3bb55c182bc19ca9d5dc2f255b",
"version" : "1.4.0"
}
},
{
"identity" : "swift-async-algorithms",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-async-algorithms.git",
"state" : {
"revision" : "6ae9a051f76b81cc668305ceed5b0e0a7fd93d20",
"version" : "1.0.1"
}
},
{
"identity" : "swift-atomics",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-atomics.git",
"state" : {
"revision" : "cd142fd2f64be2100422d658e7411e39489da985",
"version" : "1.2.0"
}
},
{
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections.git",
"state" : {
"revision" : "ee97538f5b81ae89698fd95938896dec5217b148",
"version" : "1.1.1"
}
},
{
"identity" : "swift-crypto",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-crypto.git",
"state" : {
"revision" : "46072478ca365fe48370993833cb22de9b41567f",
"version" : "3.5.2"
}
},
{
"identity" : "swift-log",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-log.git",
"state" : {
"revision" : "9cb486020ebf03bfa5b5df985387a14a98744537",
"version" : "1.6.1"
}
},
{
"identity" : "swift-metrics",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-metrics.git",
"state" : {
"revision" : "e0165b53d49b413dd987526b641e05e246782685",
"version" : "2.5.0"
}
},
{
"identity" : "swift-nio",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio.git",
"state" : {
"revision" : "fc79798d5a150d61361a27ce0c51169b889e23de",
"version" : "2.68.0"
}
},
{
"identity" : "swift-nio-ssl",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-ssl.git",
"state" : {
"revision" : "2b09805797f21c380f7dc9bedaab3157c5508efb",
"version" : "2.27.0"
}
},
{
"identity" : "swift-nio-transport-services",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-transport-services.git",
"state" : {
"revision" : "38ac8221dd20674682148d6451367f89c2652980",
"version" : "1.21.0"
}
},
{
"identity" : "swift-numerics",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-numerics",
"state" : {
"revision" : "0a5bc04095a675662cf24757cc0640aa2204253b",
"version" : "1.0.2"
}
},
{
"identity" : "swift-service-lifecycle",
"kind" : "remoteSourceControl",
"location" : "https://github.com/swift-server/swift-service-lifecycle.git",
"state" : {
"revision" : "d58e6bf2b1ae2884cf204a8b5bcaaa7aae3c1ff0",
"version" : "2.6.0"
}
},
{
"identity" : "swift-system",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-system.git",
"state" : {
"revision" : "6a9e38e7bd22a3b8ba80bddf395623cf68f57807",
"version" : "1.3.1"
}
},
{
"identity" : "texttable",
"kind" : "remoteSourceControl",
"location" : "https://github.com/ordo-one/TextTable",
"state" : {
"revision" : "a27a07300cf4ae322e0079ca0a475c5583dd575f",
"version" : "0.0.2"
}
}
],
"version" : 3
}
24 changes: 24 additions & 0 deletions Benchmarks/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// swift-tools-version: 5.10
import PackageDescription

let package = Package(
name: "Benchmarks",
platforms: [.macOS(.v14)],
dependencies: [
.package(url: "https://github.com/ordo-one/package-benchmark.git", from: "1.0.0"),
.package(path: "../../oracle-nio"),
],
targets: [
.executableTarget(
name: "OracleBench",
dependencies: [
.product(name: "Benchmark", package: "package-benchmark"),
.product(name: "OracleNIO", package: "oracle-nio"),
],
path: "Benchmarks/OracleBench",
plugins: [
.plugin(name: "BenchmarkPlugin", package: "package-benchmark")
]
)
]
)
5 changes: 1 addition & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ let package = Package(
name: "oracle-nio",
platforms: [.macOS(.v13), .iOS(.v16), .tvOS(.v16), .watchOS(.v9), .visionOS(.v1)],
products: [
.library(
name: "OracleNIO",
targets: ["OracleNIO"]
)
.library(name: "OracleNIO", targets: ["OracleNIO"])
],
dependencies: [
.package(url: "https://github.com/apple/swift-log.git", from: "1.5.4"),
Expand Down

0 comments on commit 84068c7

Please sign in to comment.