Files
swift-nio-ssl/Sources/NIOSSLPerformanceTester/Benchmark.swift
T
Cory Benfield a8dbd07f42 Add benchmarks. (#154)
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.
2019-12-02 09:39:02 +00:00

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()
}
}