| 1 |
package com.carrotsearch.hppc.benchmarks; |
| 2 |
|
| 3 |
import org.openjdk.jmh.annotations.Benchmark; |
| 4 |
import org.openjdk.jmh.annotations.BenchmarkMode; |
| 5 |
import org.openjdk.jmh.annotations.Fork; |
| 6 |
import org.openjdk.jmh.annotations.Level; |
| 7 |
import org.openjdk.jmh.annotations.Measurement; |
| 8 |
import org.openjdk.jmh.annotations.Mode; |
| 9 |
import org.openjdk.jmh.annotations.Param; |
| 10 |
import org.openjdk.jmh.annotations.Scope; |
| 11 |
import org.openjdk.jmh.annotations.Setup; |
| 12 |
import org.openjdk.jmh.annotations.State; |
| 13 |
import org.openjdk.jmh.annotations.Warmup; |
| 14 |
import org.openjdk.jmh.runner.Runner; |
| 15 |
import org.openjdk.jmh.runner.RunnerException; |
| 16 |
import org.openjdk.jmh.runner.options.Options; |
| 17 |
import org.openjdk.jmh.runner.options.OptionsBuilder; |
| 18 |
|
| 19 |
import com.carrotsearch.hppc.XorShift128P; |
| 20 |
|
| 21 |
@Fork(1) |
| 22 |
@Warmup(iterations = 5) |
| 23 |
@Measurement(iterations = 5) |
| 24 |
@State(Scope.Benchmark) |
| 25 |
public class B003_HashSet_Contains { |
| 26 |
@Param("0.75") |
| 27 |
public double loadFactor; |
| 28 |
|
| 29 |
@Param |
| 30 |
public Library library; |
| 31 |
|
| 32 |
@Param({"200"}) |
| 33 |
public int mbOfKeys; |
| 34 |
|
| 35 |
public int [] keys; |
| 36 |
public IntSetOps ops; |
| 37 |
|
| 38 |
@Setup(Level.Trial) |
| 39 |
public void prepare() { |
| 40 |
int keyCount = mbOfKeys * (1024 * 1024) / 4; |
| 41 |
keys = new int [keyCount]; |
| 42 |
|
| 43 |
XorShift128P rnd = new XorShift128P(0xdeadbeefL); |
| 44 |
for (int i = 0; i < keys.length; i++) { |
| 45 |
keys[i] = rnd.nextInt(2 * keys.length); |
| 46 |
} |
| 47 |
|
| 48 |
ops = library.newIntSet(keys.length, loadFactor); |
| 49 |
|
| 50 |
int[] existing = new int [keyCount]; |
| 51 |
for (int i = 0; i < keys.length; i++) { |
| 52 |
existing[i] = rnd.nextInt(2 * keys.length); |
| 53 |
} |
| 54 |
ops.bulkAdd(existing); |
| 55 |
} |
| 56 |
|
| 57 |
@Benchmark() |
| 58 |
@BenchmarkMode(Mode.SingleShotTime) |
| 59 |
public Object bulk() { |
| 60 |
return ops.bulkContains(keys); |
| 61 |
} |
| 62 |
|
| 63 |
public static void main(String[] args) throws RunnerException { |
| 64 |
Options opt = new OptionsBuilder().include(B003_HashSet_Contains.class.getSimpleName()).build(); |
| 65 |
new Runner(opt).run(); |
| 66 |
} |
| 67 |
} |