-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJMH_SIMD.java
More file actions
54 lines (46 loc) · 1.3 KB
/
Copy pathJMH_SIMD.java
File metadata and controls
54 lines (46 loc) · 1.3 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
package fastsimd.benchmark;
import fastmemory.Memory;
import fastpointer.Pointer;
import fastsimd.SIMD;
import org.openjdk.jmh.annotations.*;
import java.util.concurrent.TimeUnit;
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.SECONDS)
@State(Scope.Thread)
@Fork(1)
@Warmup(iterations = 2, time = 1)
@Measurement(iterations = 3, time = 1)
public class JMH_SIMD {
@Param({"10485760"}) // 10 MB
private int size;
private Memory memory;
private Pointer pointer;
private byte target = (byte) 'V';
@Setup
public void setup() {
memory = Memory.allocateAligned(size, 32);
pointer = memory.pointer();
byte[] testData = "Hello World! FastSIMD AVX2 Hardware Vector Engine Active.".getBytes();
for (int i = 0; i < size; i++) {
pointer.setByte(i, testData[i % testData.length]);
}
pointer.setByte(size - 1, target);
}
@TearDown
public void tearDown() {
if (memory != null) {
memory.free();
}
}
@Benchmark
public int testJavaSearch() {
for (int i = 0; i < size; i++) {
if (pointer.getByte(i) == target) return i;
}
return -1;
}
@Benchmark
public int testFastSIMDParallelSearch() {
return SIMD.findByte(pointer, size, target);
}
}