Repository: apple/swift-nio
File: Sources/NIOPerformanceTester/UDPBenchmark.swift (Swift)

Code before:
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftNIO open source project
//
// Copyright (c) 2023 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 NIOCore
import NIOPosix

final class UDPBenchmark {
    /// Request to send.
    private let data: ByteBuffer
    /// Number of reqeusts to send in each run.
    private let numberOfRequests: Int
    /// Setting for `.datagramVectorReadMessageCount`
    private let vectorReads: Int
    /// Number of writes before each flush (for the client; the server flushes at the end
    /// of each read cycle).
    private let vectorWrites: Int

    private var group: EventLoopGroup!
    private var server: Channel!
    private var client: Channel!
    private var clientHandler: EchoHandlerClient!

    init(data: ByteBuffer, numberOfRequests: Int, vectorReads: Int, vectorWrites: Int) {
        self.data = data
        self.numberOfRequests = numberOfRequests
        self.vectorReads = vectorReads
        self.vectorWrites = vectorWrites
    }
}

extension UDPBenchmark: Benchmark {
    func setUp() throws {
        self.group = MultiThreadedEventLoopGroup(numberOfThreads: 1)

        let address = try SocketAddress.makeAddressResolvingHost("127.0.0.1", port: 0)

Review comment (suggestion):
Nit: 
```suggestion
    /// Number of requests to send in each run.
```

Code after:
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftNIO open source project
//
// Copyright (c) 2023 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 NIOCore
import NIOPosix

final class UDPBenchmark {
    /// Request to send.
    private let data: ByteBuffer
    /// Number of requests to send in each run.
    private let numberOfRequests: Int
    /// Setting for `.datagramVectorReadMessageCount`
    private let vectorReads: Int
    /// Number of writes before each flush (for the client; the server flushes at the end
    /// of each read cycle).
    private let vectorWrites: Int

    private var group: EventLoopGroup!
    private var server: Channel!
    private var client: Channel!
    private var clientHandler: EchoHandlerClient!

    init(data: ByteBuffer, numberOfRequests: Int, vectorReads: Int, vectorWrites: Int) {
        self.data = data
        self.numberOfRequests = numberOfRequests
        self.vectorReads = vectorReads
        self.vectorWrites = vectorWrites
    }
}

extension UDPBenchmark: Benchmark {
    func setUp() throws {
        self.group = MultiThreadedEventLoopGroup(numberOfThreads: 1)

        let address = try SocketAddress.makeAddressResolvingHost("127.0.0.1", port: 0)