Skip to content

Commit

Permalink
More timing tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanLennox committed Oct 15, 2024
1 parent d2e792a commit 0800279
Showing 1 changed file with 25 additions and 29 deletions.
54 changes: 25 additions & 29 deletions src/test/kotlin/org/ice4j/socket/SocketPoolTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -174,40 +174,36 @@ class SocketPoolTest : ShouldSpec() {
return Sender.elapsed
}

fun testSendingOnce(numSockets: Int, numThreads: Int, warmup: Boolean = false) {
val pool = SocketPool(loopbackAny, numSockets)
val elapsed = sendTimeOnAllSockets(pool, numThreads)
if (!warmup) {
println("Send ${Sender.NUM_PACKETS} packets on ${numSockets} sockets on ${numThreads} threads " +
"took $elapsed"
)
}
}

fun testSending() {
val poolWarmup = SocketPool(loopbackAny, 1)
sendTimeOnAllSockets(poolWarmup)
testSendingOnce(1, 1, warmup = true)

val pool1 = SocketPool(loopbackAny, 1)
val elapsed11 = sendTimeOnAllSockets(pool1)
println("Send ${Sender.NUM_PACKETS} packets on 1 socket on one thread took $elapsed11")
testSendingOnce(1, 1)

val numProcessors = Runtime.getRuntime().availableProcessors()

val elapsed1N = sendTimeOnAllSockets(pool1, numProcessors)
println(
"Send ${Sender.NUM_PACKETS} packets on 1 socket on $numProcessors threads took $elapsed1N"
)

val poolN = SocketPool(loopbackAny, numProcessors)
val elapsedNN = sendTimeOnAllSockets(poolN, numProcessors)
println(
"Send ${Sender.NUM_PACKETS} packets on $numProcessors sockets on $numProcessors threads " +
"took $elapsedNN"
)

val elapsedN2N = sendTimeOnAllSockets(poolN, 2 * numProcessors)
println(
"Send ${Sender.NUM_PACKETS} packets on $numProcessors sockets on ${2 * numProcessors} threads " +
"took $elapsedN2N"
)

val pool2N = SocketPool(loopbackAny, 2 * numProcessors)
val elapsed2N2N = sendTimeOnAllSockets(pool2N, 2 * numProcessors)
println(
"Send ${Sender.NUM_PACKETS} packets on ${2 * numProcessors} sockets " +
"on ${2 * numProcessors} threads took $elapsed2N2N"
)
testSendingOnce(1, numProcessors)

testSendingOnce(numProcessors, numProcessors)

testSendingOnce(numProcessors, 2 * numProcessors)

testSendingOnce(2 * numProcessors, 2 * numProcessors)

testSendingOnce(2 * numProcessors, 4 * numProcessors)

testSendingOnce(4 * numProcessors, 4 * numProcessors)

testSendingOnce(4 * numProcessors, 8 * numProcessors)
}

@JvmStatic
Expand Down

0 comments on commit 0800279

Please sign in to comment.