//===----------------------------------------------------------------------===// // // 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 // //===----------------------------------------------------------------------===// import NIO import NIOHPACK /// This benchmark is mostly attempting to stress the Huffman Encoding implementation by /// way of using larger or more complex strings. final class HuffmanEncodingBenchmark { private var headers: HPACKHeaders private let loopCount: Int private var encoder: HPACKEncoder private var buffer: ByteBuffer init(huffmanString: String, loopCount: Int) { self.headers = HPACKHeaders() self.headers.add(name: "f", value: huffmanString, indexing: .neverIndexed) self.loopCount = loopCount self.encoder = HPACKEncoder(allocator: .init()) self.buffer = ByteBufferAllocator().buffer(capacity: 1024) } } extension HuffmanEncodingBenchmark: Benchmark { func setUp() throws { // Run a single iteration of the loop. This warms up the encoder and decoder and ensures all the pages are mapped. try self.loopIteration() } func tearDown() { } func run() throws -> Int { for _ in 0..