| 1 |
package com.carrotsearch.hppc.benchmarks; |
| 2 |
|
| 3 |
import org.openjdk.jmh.annotations.Benchmark; |
| 4 |
import org.openjdk.jmh.annotations.Fork; |
| 5 |
import org.openjdk.jmh.annotations.Measurement; |
| 6 |
import org.openjdk.jmh.annotations.Scope; |
| 7 |
import org.openjdk.jmh.annotations.State; |
| 8 |
import org.openjdk.jmh.annotations.Warmup; |
| 9 |
import org.openjdk.jmh.runner.Runner; |
| 10 |
import org.openjdk.jmh.runner.RunnerException; |
| 11 |
import org.openjdk.jmh.runner.options.Options; |
| 12 |
import org.openjdk.jmh.runner.options.OptionsBuilder; |
| 13 |
|
| 14 |
@Fork(1) |
| 15 |
@Warmup(iterations = 5) |
| 16 |
@Measurement(iterations = 5) |
| 17 |
@State(Scope.Thread) |
| 18 |
public class B001_ModXor { |
| 19 |
private int v; |
| 20 |
private int mask = 0x238751; |
| 21 |
|
| 22 |
@Benchmark |
| 23 |
public int modOp() { |
| 24 |
v = v % mask++; |
| 25 |
return v; |
| 26 |
} |
| 27 |
|
| 28 |
@Benchmark |
| 29 |
public int xorOp() { |
| 30 |
v = v ^ mask++; |
| 31 |
return v; |
| 32 |
} |
| 33 |
|
| 34 |
public static void main(String[] args) throws RunnerException { |
| 35 |
Options opt = new OptionsBuilder() |
| 36 |
.include(B001_ModXor.class.getSimpleName()) |
| 37 |
.build(); |
| 38 |
|
| 39 |
new Runner(opt).run(); |
| 40 |
} |
| 41 |
} |