-
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.
Add JMH benchmarks for Lucene IntIntHashMap and Eclipse IntShortHashM…
…ap (#599)
- Loading branch information
1 parent
bf38104
commit 956cdfc
Showing
4 changed files
with
75 additions
and
7 deletions.
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
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
63 changes: 63 additions & 0 deletions
63
...-benchmarks/src/main/scala/com/klibisz/elastiknn/jmhbenchmarks/HitCounterBenchmarks.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,63 @@ | ||
package com.klibisz.elastiknn.jmhbenchmarks | ||
|
||
import org.openjdk.jmh.annotations._ | ||
import org.apache.lucene.util.hppc.IntIntHashMap | ||
import org.eclipse.collections.impl.map.mutable.primitive.IntShortHashMap | ||
|
||
import scala.util.Random | ||
|
||
@State(Scope.Benchmark) | ||
class HitCounterBenchmarksFixtures { | ||
val rng = new Random(0) | ||
val numDocs = 60000 | ||
val numHits = 2000 | ||
val initialMapSize = 1000 | ||
val docs = (1 to numHits).map(_ => rng.nextInt(numDocs)).toArray | ||
} | ||
|
||
class HitCounterBenchmarks { | ||
|
||
@Benchmark | ||
@BenchmarkMode(Array(Mode.Throughput)) | ||
@Fork(value = 1) | ||
@Warmup(time = 5, iterations = 5) | ||
@Measurement(time = 5, iterations = 5) | ||
def arrayCountBaseline(f: HitCounterBenchmarksFixtures): Unit = { | ||
val arr = new Array[Int](f.numDocs) | ||
for (d <- f.docs) arr.update(d, arr(d) + 1) | ||
() | ||
} | ||
|
||
@Benchmark | ||
@BenchmarkMode(Array(Mode.Throughput)) | ||
@Fork(value = 1) | ||
@Warmup(time = 5, iterations = 5) | ||
@Measurement(time = 5, iterations = 5) | ||
def hashMapGetOrDefault(f: HitCounterBenchmarksFixtures): Unit = { | ||
val h = new java.util.HashMap[Int, Int](f.initialMapSize, 0.99f) | ||
for (d <- f.docs) h.put(d, h.getOrDefault(d, 0) + 1) | ||
() | ||
} | ||
|
||
@Benchmark | ||
@BenchmarkMode(Array(Mode.Throughput)) | ||
@Fork(value = 1) | ||
@Warmup(time = 5, iterations = 5) | ||
@Measurement(time = 5, iterations = 5) | ||
def luceneIntIntHashMap(f: HitCounterBenchmarksFixtures): Unit = { | ||
val m = new IntIntHashMap(f.initialMapSize, 0.99d) | ||
for (d <- f.docs) m.putOrAdd(d, 1, 1) | ||
() | ||
} | ||
|
||
@Benchmark | ||
@BenchmarkMode(Array(Mode.Throughput)) | ||
@Fork(value = 1) | ||
@Warmup(time = 5, iterations = 5) | ||
@Measurement(time = 5, iterations = 5) | ||
def eclipseIntShortHashMapAddToValue(f: HitCounterBenchmarksFixtures): Unit = { | ||
val m = new IntShortHashMap(f.initialMapSize) | ||
for (d <- f.docs) m.addToValue(d, 1) | ||
() | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
...tiknn/vectors/VectorOpsJmhBenchmark.scala → ...jmhbenchmarks/VectorOpsJmhBenchmark.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