-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added jmh benchmark for FLoatArrayBuffer
- Loading branch information
1 parent
e2b4da0
commit 3842f08
Showing
2 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...marks/src/main/scala/com/klibisz/elastiknn/jmhbenchmarks/FloatArrayBufferBenchmarks.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.klibisz.elastiknn.jmhbenchmarks | ||
|
||
import com.klibisz.elastiknn.api.FloatArrayBuffer | ||
import org.openjdk.jmh.annotations._ | ||
|
||
import scala.collection.mutable.ArrayBuffer | ||
import scala.util.Random | ||
|
||
@State(Scope.Benchmark) | ||
class FloatArrayBufferBenchmarksState { | ||
implicit private val rng: Random = new Random(0) | ||
val lst768 = (0 until 768).map(_ => rng.nextFloat()).toList | ||
} | ||
|
||
class FloatArrayBufferBenchmarks { | ||
|
||
@Benchmark | ||
@BenchmarkMode(Array(Mode.Throughput)) | ||
@Fork(value = 1) | ||
@Warmup(time = 5, iterations = 1) | ||
@Measurement(time = 5, iterations = 1) | ||
def scalaAppendFixedInitialSize(state: FloatArrayBufferBenchmarksState): Int = { | ||
val buf = new ArrayBuffer[Float]() | ||
state.lst768.foreach(buf.append) | ||
buf.toArray.length | ||
} | ||
|
||
@Benchmark | ||
@BenchmarkMode(Array(Mode.Throughput)) | ||
@Fork(value = 1) | ||
@Warmup(time = 5, iterations = 1) | ||
@Measurement(time = 5, iterations = 1) | ||
def scalaAppendKnownInitialSize(state: FloatArrayBufferBenchmarksState): Int = { | ||
val buf = new ArrayBuffer[Float](768) | ||
state.lst768.foreach(buf.append) | ||
buf.toArray.length | ||
} | ||
|
||
@Benchmark | ||
@BenchmarkMode(Array(Mode.Throughput)) | ||
@Fork(value = 1) | ||
@Warmup(time = 5, iterations = 1) | ||
@Measurement(time = 5, iterations = 1) | ||
def customAppend(state: FloatArrayBufferBenchmarksState): Int = { | ||
val buf = new FloatArrayBuffer() | ||
state.lst768.foreach(buf.append) | ||
buf.toArray.length | ||
} | ||
} |