-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJMH_Search.java
More file actions
41 lines (34 loc) · 931 Bytes
/
JMH_Search.java
File metadata and controls
41 lines (34 loc) · 931 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package fastbytes.benchmark;
import fastbytes.FastBytes;
import org.openjdk.jmh.annotations.*;
import java.util.concurrent.TimeUnit;
import java.util.Arrays;
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.SECONDS)
@State(Scope.Thread)
@Fork(1)
@Warmup(iterations = 2, time = 1)
@Measurement(iterations = 3, time = 1)
public class JMH_Search {
@Param({"104857600"}) // 100MB
private int size;
private byte[] data;
private byte target = (byte) 0xEE;
@Setup
public void setup() {
data = new byte[size];
Arrays.fill(data, (byte) 0);
data[size - 1] = target; // Force full scan
}
@Benchmark
public int testJavaSearch() {
for (int i = 0; i < data.length; i++) {
if (data[i] == target) return i;
}
return -1;
}
@Benchmark
public int testFastBytesSearch() {
return FastBytes.indexOf(data, target);
}
}