Skip to content

Commit

Permalink
Add byte[]-based Kryo benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
szeiger committed Nov 23, 2024
1 parent c309aba commit e2e2c1e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
10 changes: 7 additions & 3 deletions bench/src/main/scala/perfio/BufferedInputNumBenchmark.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package perfio

import com.esotericsoftware.kryo.io.{ByteBufferInput, Input}
import com.esotericsoftware.kryo.unsafe.UnsafeByteBufferInput
import com.esotericsoftware.kryo.unsafe.{UnsafeByteBufferInput, UnsafeInput}
import org.openjdk.jmh.annotations.*
import org.openjdk.jmh.infra.*

Expand Down Expand Up @@ -90,9 +90,13 @@ class BufferedInputNumBenchmark extends BenchUtil {
@Benchmark
def array_DataInputStream(bh: Blackhole): Unit = run(bh, new DataInputStream(new ByteArrayInputStream(testData)))
@Benchmark
def array_Kryo(bh: Blackhole): Unit = run(bh, new ByteBufferInput(testData))
def array_Kryo(bh: Blackhole): Unit = run(bh, new Input(testData))
@Benchmark
def array_KryoUnsafe(bh: Blackhole): Unit = run(bh, new UnsafeByteBufferInput(testData))
def array_KryoUnsafe(bh: Blackhole): Unit = run(bh, new UnsafeInput(testData))
@Benchmark
def array_KryoBB(bh: Blackhole): Unit = run(bh, new ByteBufferInput(testData))
@Benchmark
def array_KryoBBUnsafe(bh: Blackhole): Unit = run(bh, new UnsafeByteBufferInput(testData))
@Benchmark
def array_ByteBuffer(bh: Blackhole): Unit = run(bh, ByteBuffer.wrap(testData))
@Benchmark
Expand Down
41 changes: 35 additions & 6 deletions bench/src/main/scala/perfio/BufferedOutputNumBenchmark.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package perfio

import com.esotericsoftware.kryo.io.{ByteBufferOutput, Output}
import com.esotericsoftware.kryo.unsafe.UnsafeByteBufferOutput
import com.esotericsoftware.kryo.unsafe.{UnsafeByteBufferOutput, UnsafeOutput}
import org.openjdk.jmh.annotations.*
import org.openjdk.jmh.infra.*
import perfio.internal.BufferUtil
Expand All @@ -17,8 +17,8 @@ import java.util.concurrent.TimeUnit
"--add-opens", "java.base/sun.nio.ch=ALL-UNNAMED" // for KryoUnsafe
))
@Threads(1)
@Warmup(iterations = 15, time = 1)
@Measurement(iterations = 15, time = 1)
@Warmup(iterations = 25, time = 1)
@Measurement(iterations = 10, time = 1)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@State(Scope.Benchmark)
class BufferedOutputNumBenchmark extends BenchUtil:
Expand Down Expand Up @@ -84,28 +84,57 @@ class BufferedOutputNumBenchmark extends BenchUtil:
@Benchmark
def array_Kryo_growing(bh: Blackhole): Unit =
val bout = new MyByteArrayOutputStream
val out = new ByteBufferOutput(bout)
val out = new Output(bout)
writeTo(out)
bh.consume(bout.getSize)
bh.consume(bout.getBuffer)

@Benchmark
def array_Kryo_preallocated(bh: Blackhole): Unit =
val out = new Output(count * 13)
writeTo(out)
bh.consume(out.position())

@Benchmark
def array_KryoUnsafe_growing(bh: Blackhole): Unit =
val bout = new MyByteArrayOutputStream
val out = new UnsafeOutput(bout)
writeTo(out)
bh.consume(bout.getSize)
bh.consume(bout.getBuffer)

@Benchmark
def array_KryoUnsafe_preallocated(bh: Blackhole): Unit =
val bb = ByteBuffer.allocate(count * 13)
val out = new UnsafeOutput(count * 13)
writeTo(out)
bh.consume(out.position())

@Benchmark
def array_KryoBB_growing(bh: Blackhole): Unit =
val bout = new MyByteArrayOutputStream
val out = new ByteBufferOutput(bout)
writeTo(out)
bh.consume(bout.getSize)
bh.consume(bout.getBuffer)

@Benchmark
def array_KryoBB_preallocated(bh: Blackhole): Unit =
val bb = ByteBuffer.allocate(count * 13)
val out = new ByteBufferOutput(bb)
writeTo(out)
bh.consume(out.position())

@Benchmark
def array_KryoUnsafe_growing(bh: Blackhole): Unit =
def array_KryoBBUnsafe_growing(bh: Blackhole): Unit =
val bout = new MyByteArrayOutputStream
val out = new UnsafeByteBufferOutput(bout)
writeTo(out)
bh.consume(bout.getSize)
bh.consume(bout.getBuffer)

@Benchmark
def array_KryoUnsafe_preallocated(bh: Blackhole): Unit =
def array_KryoBBUnsafe_preallocated(bh: Blackhole): Unit =
val bb = ByteBuffer.allocate(count * 13)
val out = new UnsafeByteBufferOutput(count * 13)
writeTo(out)
Expand Down

0 comments on commit e2e2c1e

Please sign in to comment.