Skip to content

Added initial benchmarks #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixups
  • Loading branch information
czechboy0 committed Oct 2, 2024
commit 37e8fae647425803a5fd6b95739e091a430c7bd9
14 changes: 14 additions & 0 deletions Benchmarks/Sources/Benchmarks.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftOpenAPIGenerator open source project
//
// Copyright (c) YEARS Apple Inc. and the SwiftOpenAPIGenerator project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftOpenAPIGenerator project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

import Benchmark
@_spi(Benchmarks) import OpenAPIAsyncHTTPClient
import AsyncHTTPClient
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/apple/swift-nio", from: "2.58.0"),
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.19.0"),
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.23.0"),
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.0.0"),
.package(url: "https://github.com/apple/swift-http-types", from: "1.0.0"),
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
Expand Down
27 changes: 10 additions & 17 deletions Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,24 +130,18 @@ public struct AsyncHTTPClientTransport: ClientTransport {
/// - Parameters:
/// - configuration: A set of configuration values used by the transport.
/// - requestSender: The underlying request sender closure.
@_spi(Benchmarks)
public init(
@_spi(Benchmarks) public init(
configuration: Configuration,
requestSenderClosure: @Sendable @escaping (HTTPClientRequest, HTTPClient, TimeAmount) async throws -> HTTPClientResponse
requestSenderClosure: @Sendable @escaping (HTTPClientRequest, HTTPClient, TimeAmount) async throws ->
HTTPClientResponse
) {
struct ClosureRequestSender: HTTPRequestSending {
var sendClosure: @Sendable (
AsyncHTTPClientTransport.Request,
HTTPClient,
TimeAmount
) async throws -> AsyncHTTPClientTransport.Response
func send(
request: AsyncHTTPClientTransport.Request,
with client: HTTPClient,
timeout: TimeAmount
) async throws -> AsyncHTTPClientTransport.Response {
try await sendClosure(request, client, timeout)
}
var sendClosure:
@Sendable (AsyncHTTPClientTransport.Request, HTTPClient, TimeAmount) async throws ->
AsyncHTTPClientTransport.Response
func send(request: AsyncHTTPClientTransport.Request, with client: HTTPClient, timeout: TimeAmount)
async throws -> AsyncHTTPClientTransport.Response
{ try await sendClosure(request, client, timeout) }
}
self.configuration = configuration
self.requestSender = ClosureRequestSender(sendClosure: requestSenderClosure)
Expand Down Expand Up @@ -201,8 +195,7 @@ public struct AsyncHTTPClientTransport: ClientTransport {
let length: HTTPClientRequest.Body.Length
switch body.length {
case .unknown: length = .unknown
case .known(let count):
if let intValue = Int(exactly: count) { length = .known(intValue) } else { length = .unknown }
case .known(let count): length = .known(count)
}
clientRequest.body = .stream(body.map { .init(bytes: $0) }, length: length)
}
Expand Down
3 changes: 3 additions & 0 deletions scripts/check-license-headers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ read -ra PATHS_TO_CHECK_FOR_LICENSE <<< "$( \
":(exclude).gitignore" \
":(exclude).spi.yml" \
":(exclude).swift-format" \
":(exclude)Benchmarks/.gitignore" \
":(exclude)Benchmarks/Package.swift" \
":(exclude)Benchmarks/README.md" \
":(exclude)CODE_OF_CONDUCT.md" \
":(exclude)CONTRIBUTING.md" \
":(exclude)CONTRIBUTORS.txt" \
Expand Down