Skip to content

Commit

Permalink
Add Package.swift and Benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler committed Nov 22, 2024
1 parent a862f86 commit 18984fd
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 30 deletions.
8 changes: 4 additions & 4 deletions Benchmarks/Benchmarks/Router/Benchmarks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import Hummingbird

let benchmarks = {
Benchmark.defaultConfiguration = .init(
metrics: ProcessInfo.processInfo.environment["CI"] != nil ?
[
metrics: ProcessInfo.processInfo.environment["CI"] != nil
? [
.instructions,
.mallocCountTotal,
] :
[
]
: [
.cpuTotal,
.instructions,
.mallocCountTotal,
Expand Down
28 changes: 20 additions & 8 deletions Benchmarks/Benchmarks/Router/RouterBenchmarks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ extension Benchmark {
request: HTTPRequest,
writeBody: (@Sendable (ByteBufferWriter) async throws -> Void)? = nil,
createRouter: @escaping @Sendable () async throws -> ResponderBuilder
) where ResponderBuilder.Responder.Context: RequestContext, ResponderBuilder.Responder.Context.Source == BenchmarkRequestContextSource {
)
where
ResponderBuilder.Responder.Context: RequestContext,
ResponderBuilder.Responder.Context.Source == BenchmarkRequestContextSource
{
self.init(name, configuration: configuration) { benchmark in
let responder = try await createRouter().buildResponder()

Expand Down Expand Up @@ -105,8 +109,12 @@ extension Benchmark {
}

struct EmptyMiddleware<Context>: RouterMiddleware {
func handle(_ request: Request, context: Context, next: (Request, Context) async throws -> Response) async throws -> Response {
return try await next(request, context)
func handle(
_ request: Request,
context: Context,
next: (Request, Context) async throws -> Response
) async throws -> Response {
try await next(request, context)
}
}

Expand Down Expand Up @@ -170,12 +178,16 @@ func routerBenchmarks() {
} createRouter: {
let router = Router(context: BasicBenchmarkContext.self)
router.post { request, _ in
Response(status: .ok, headers: [:], body: .init { writer in
for try await buffer in request.body {
try await writer.write(buffer)
Response(
status: .ok,
headers: [:],
body: .init { writer in
for try await buffer in request.body {
try await writer.write(buffer)
}
try await writer.finish(nil)
}
try await writer.finish(nil)
})
)
}
return router
}
Expand Down
5 changes: 4 additions & 1 deletion Benchmarks/Benchmarks/Router/TrieRouterBenchmarks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ func trieRouterBenchmarks() {
}
} setup: {
let trieBuilder = RouterPathTrieBuilder<String>()
trieBuilder.addEntry("/api/v1/a/very/long/path/with/lots/of/segments", value: "/api/v1/a/very/long/path/with/lots/of/segments")
trieBuilder.addEntry(
"/api/v1/a/very/long/path/with/lots/of/segments",
value: "/api/v1/a/very/long/path/with/lots/of/segments"
)
trieBuilder.addEntry("/api/v1/users/:id/profile", value: "/api/v1/users/:id/profile")
trie3 = RouterTrie(base: trieBuilder)
}
Expand Down
4 changes: 2 additions & 2 deletions Benchmarks/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ let package = Package(
],
path: "Benchmarks/Router",
plugins: [
.plugin(name: "BenchmarkPlugin", package: "package-benchmark"),
.plugin(name: "BenchmarkPlugin", package: "package-benchmark")
]
),
)
]
)
34 changes: 19 additions & 15 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,21 +123,26 @@ let package = Package(
swiftSettings: [.enableExperimentalFeature("StrictConcurrency=complete")]
),
// test targets
.testTarget(name: "HummingbirdTests", dependencies: [
.byName(name: "Hummingbird"),
.byName(name: "HummingbirdTLS"),
.byName(name: "HummingbirdHTTP2"),
.byName(name: "HummingbirdTesting"),
.byName(name: "HummingbirdRouter"),
]),
.testTarget(name: "HummingbirdRouterTests", dependencies: [
.byName(name: "HummingbirdRouter"),
.byName(name: "HummingbirdTesting"),
]),
.testTarget(
name: "HummingbirdTests",
dependencies: [
.byName(name: "Hummingbird"),
.byName(name: "HummingbirdTLS"),
.byName(name: "HummingbirdHTTP2"),
.byName(name: "HummingbirdTesting"),
.byName(name: "HummingbirdRouter"),
]
),
.testTarget(
name: "HummingbirdRouterTests",
dependencies: [
.byName(name: "HummingbirdRouter"),
.byName(name: "HummingbirdTesting"),
]
),
.testTarget(
name: "HummingbirdCoreTests",
dependencies:
[
dependencies: [
.byName(name: "HummingbirdCore"),
.byName(name: "HummingbirdTLS"),
.byName(name: "HummingbirdTesting"),
Expand All @@ -147,8 +152,7 @@ let package = Package(
),
.testTarget(
name: "HummingbirdHTTP2Tests",
dependencies:
[
dependencies: [
.byName(name: "HummingbirdCore"),
.byName(name: "HummingbirdHTTP2"),
.byName(name: "HummingbirdTesting"),
Expand Down

0 comments on commit 18984fd

Please sign in to comment.