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 24, 2024
1 parent c309aba commit b11fd32
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 10 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
66 changes: 59 additions & 7 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 Expand Up @@ -179,4 +208,27 @@ class BufferedOutputNumBenchmark extends BenchUtil:
def file_FlushingBufferedOutput(bh: Blackhole): Unit =
val out = BufferedOutput.ofFile(Paths.get("/dev/null"))
writeTo(out)
out.close()

@Benchmark
def file_Kryo(bh: Blackhole): Unit =
val fout = new FileOutputStream("/dev/null")
val out = new Output(fout)
writeTo(out)

@Benchmark
def file_KryoUnsafe(bh: Blackhole): Unit =
val fout = new FileOutputStream("/dev/null")
val out = new UnsafeOutput(fout)
writeTo(out)

@Benchmark
def file_KryoBB(bh: Blackhole): Unit =
val fout = new FileOutputStream("/dev/null")
val out = new ByteBufferOutput(fout)
writeTo(out)

@Benchmark
def file_KryoBBUnsafe(bh: Blackhole): Unit =
val fout = new FileOutputStream("/dev/null")
val out = new UnsafeByteBufferOutput(fout)
writeTo(out)

0 comments on commit b11fd32

Please sign in to comment.