Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add benchmark testing with Utils.BenchMark
  • Loading branch information
caneGuy committed Aug 24, 2017
commit ca77b51549f8be32f14565ac5ea94a8b83386afd
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ package org.apache.spark.io
import java.nio.ByteBuffer

import com.google.common.io.ByteStreams

import org.apache.spark.SparkFunSuite
import org.apache.spark.network.util.ByteArrayWritableChannel
import org.apache.spark.util.Benchmark
import org.apache.spark.util.io.ChunkedByteBuffer

class ChunkedByteBufferSuite extends SparkFunSuite {
Expand Down Expand Up @@ -56,6 +56,33 @@ class ChunkedByteBufferSuite extends SparkFunSuite {
assert(chunkedByteBuffer.getChunks().head.position() === 0)
}

test("benchmark testing for writeWithSlice()and writeFully()") {
val benchmark = new Benchmark("Benchmark writeWithSlice() and writeFully()", 1024 * 1024 * 15)
val buffer100 = ByteBuffer.allocate(1024 * 1024 * 100)
val buffer30 = ByteBuffer.allocate(1024 * 1024 * 30)
val chunkedByteBuffer30m = new ChunkedByteBuffer(Array.fill(10)(buffer30))
val chunkedByteBuffer100m = new ChunkedByteBuffer(Array.fill(10)(buffer100))

benchmark.addCase("Test writeFully() chunks each with 30m for 10 loop", 10) { _ =>
chunkedByteBuffer30m.writeFully(
new ByteArrayWritableChannel(chunkedByteBuffer30m.size.toInt))
}
benchmark.addCase("Test writeWithSlice() chunks each with 30m for 10 loop", 10) { _ =>
chunkedByteBuffer30m.writeWithSlice(
new ByteArrayWritableChannel(chunkedByteBuffer30m.size.toInt))
}

benchmark.addCase("Test writeFully() chunks each with 100m for 50 loop", 50) { _ =>
chunkedByteBuffer30m.writeFully(
new ByteArrayWritableChannel(chunkedByteBuffer30m.size.toInt))
}
benchmark.addCase("Test writeWithSlice() chunks each with 100m for 50 loop", 50) { _ =>
chunkedByteBuffer30m.writeWithSlice(
new ByteArrayWritableChannel(chunkedByteBuffer30m.size.toInt))
}
benchmark.run()
}

test("toArray()") {
val empty = ByteBuffer.wrap(Array.empty[Byte])
val bytes = ByteBuffer.wrap(Array.tabulate(8)(_.toByte))
Expand Down