mirror of
https://github.com/apple/swift-nio-ssl
synced 2026-11-26 04:57:52 +00:00
Motivation: When working with performance its useful to know what your approximate throughput is. One of the ways we find this out in NIO is to add benchmarks that let you know what the approximate runtime of a simple sample program is. NIOSSL doesn't have any of these: it should. Modifications: Bring across the benchmark framework from other NIO projects. Add two benchmarks mirroring the proposed allocation counter tests. Result: Insight into performance.
30 lines
817 B
Swift
30 lines
817 B
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the SwiftNIO open source project
|
|
//
|
|
// Copyright (c) 2019 Apple Inc. and the SwiftNIO project authors
|
|
// Licensed under Apache License v2.0
|
|
//
|
|
// See LICENSE.txt for license information
|
|
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
protocol Benchmark: class {
|
|
func setUp() throws
|
|
func tearDown()
|
|
func run() throws -> Int
|
|
}
|
|
|
|
func measureAndPrint<B: Benchmark>(desc: String, benchmark bench: B) throws {
|
|
try bench.setUp()
|
|
defer {
|
|
bench.tearDown()
|
|
}
|
|
try measureAndPrint(desc: desc) {
|
|
return try bench.run()
|
|
}
|
|
}
|