32 import org.openjdk.jmh.annotations.Mode;
33 import org.openjdk.jmh.annotations.OutputTimeUnit;
34 import org.openjdk.jmh.annotations.Setup;
35 import org.openjdk.jmh.annotations.State;
36 import org.openjdk.jmh.annotations.TearDown;
37 import org.openjdk.jmh.annotations.Warmup;
38
39 import java.nio.ByteBuffer;
40 import java.nio.ByteOrder;
41 import java.nio.IntBuffer;
42 import java.util.Iterator;
43 import java.util.concurrent.TimeUnit;
44
45 import static java.lang.foreign.ValueLayout.JAVA_INT;
46
47 @BenchmarkMode(Mode.AverageTime)
48 @Warmup(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS)
49 @Measurement(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
50 @State(org.openjdk.jmh.annotations.Scope.Thread)
51 @OutputTimeUnit(TimeUnit.MILLISECONDS)
52 @Fork(value = 3, jvmArgsAppend = { "--enable-preview", "--enable-native-access=ALL-UNNAMED" })
53
54 public class LoopOverSlice {
55
56 static final int ELEM_SIZE = 1_000_000;
57 static final int CARRIER_SIZE = (int)JAVA_INT.byteSize();
58 static final int ALLOC_SIZE = ELEM_SIZE * CARRIER_SIZE;
59
60 Arena arena;
61 MemorySegment nativeSegment, heapSegment;
62 IntBuffer nativeBuffer, heapBuffer;
63
64 @Setup
65 public void setup() {
66 arena = Arena.ofConfined();
67 nativeSegment = arena.allocate(ALLOC_SIZE, 1);
68 heapSegment = MemorySegment.ofArray(new int[ELEM_SIZE]);
69 nativeBuffer = ByteBuffer.allocateDirect(ALLOC_SIZE).order(ByteOrder.LITTLE_ENDIAN).asIntBuffer();
70 heapBuffer = IntBuffer.wrap(new int[ELEM_SIZE]);
71 }
72
|
32 import org.openjdk.jmh.annotations.Mode;
33 import org.openjdk.jmh.annotations.OutputTimeUnit;
34 import org.openjdk.jmh.annotations.Setup;
35 import org.openjdk.jmh.annotations.State;
36 import org.openjdk.jmh.annotations.TearDown;
37 import org.openjdk.jmh.annotations.Warmup;
38
39 import java.nio.ByteBuffer;
40 import java.nio.ByteOrder;
41 import java.nio.IntBuffer;
42 import java.util.Iterator;
43 import java.util.concurrent.TimeUnit;
44
45 import static java.lang.foreign.ValueLayout.JAVA_INT;
46
47 @BenchmarkMode(Mode.AverageTime)
48 @Warmup(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS)
49 @Measurement(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
50 @State(org.openjdk.jmh.annotations.Scope.Thread)
51 @OutputTimeUnit(TimeUnit.MILLISECONDS)
52 @Fork(value = 3, jvmArgsAppend = { "--enable-native-access=ALL-UNNAMED" })
53
54 public class LoopOverSlice {
55
56 static final int ELEM_SIZE = 1_000_000;
57 static final int CARRIER_SIZE = (int)JAVA_INT.byteSize();
58 static final int ALLOC_SIZE = ELEM_SIZE * CARRIER_SIZE;
59
60 Arena arena;
61 MemorySegment nativeSegment, heapSegment;
62 IntBuffer nativeBuffer, heapBuffer;
63
64 @Setup
65 public void setup() {
66 arena = Arena.ofConfined();
67 nativeSegment = arena.allocate(ALLOC_SIZE, 1);
68 heapSegment = MemorySegment.ofArray(new int[ELEM_SIZE]);
69 nativeBuffer = ByteBuffer.allocateDirect(ALLOC_SIZE).order(ByteOrder.LITTLE_ENDIAN).asIntBuffer();
70 heapBuffer = IntBuffer.wrap(new int[ELEM_SIZE]);
71 }
72
|