41 import java.util.concurrent.TimeUnit;
42
43 import static java.lang.foreign.ValueLayout.JAVA_INT;
44
45 @BenchmarkMode(Mode.AverageTime)
46 @Warmup(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS)
47 @Measurement(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
48 @State(org.openjdk.jmh.annotations.Scope.Thread)
49 @OutputTimeUnit(TimeUnit.MILLISECONDS)
50 @Fork(value = 3, jvmArgs = { "--add-opens=java.base/jdk.internal.misc=ALL-UNNAMED" })
51 public class LoopOverPollutedBuffer {
52
53 static final int ELEM_SIZE = 1_000_000;
54 static final int CARRIER_SIZE = (int) JAVA_INT.byteSize();
55 static final int ALLOC_SIZE = ELEM_SIZE * CARRIER_SIZE;
56
57 static final Unsafe unsafe = Utils.unsafe;
58
59 ByteBuffer dbb = ByteBuffer.allocateDirect(ALLOC_SIZE).order(ByteOrder.nativeOrder());
60 byte[] arr = new byte[ALLOC_SIZE];
61 ByteBuffer hbb = ByteBuffer.wrap(arr).order(ByteOrder.nativeOrder());
62 FloatBuffer hfb = hbb.asFloatBuffer();
63
64
65 @Setup
66 public void setup() {
67 for (int i = 0; i < ELEM_SIZE; i++) {
68 dbb.putFloat(i * 4, i);
69 hbb.putFloat(i * 4, i);
70 }
71 for (int i = 0; i < ELEM_SIZE; i++) {
72 hfb.put(i, i);
73 }
74 }
75
76 @TearDown
77 public void tearDown() {
78 unsafe.invokeCleaner(dbb);
79 arr = null;
80 hbb = null;
|
41 import java.util.concurrent.TimeUnit;
42
43 import static java.lang.foreign.ValueLayout.JAVA_INT;
44
45 @BenchmarkMode(Mode.AverageTime)
46 @Warmup(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS)
47 @Measurement(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
48 @State(org.openjdk.jmh.annotations.Scope.Thread)
49 @OutputTimeUnit(TimeUnit.MILLISECONDS)
50 @Fork(value = 3, jvmArgs = { "--add-opens=java.base/jdk.internal.misc=ALL-UNNAMED" })
51 public class LoopOverPollutedBuffer {
52
53 static final int ELEM_SIZE = 1_000_000;
54 static final int CARRIER_SIZE = (int) JAVA_INT.byteSize();
55 static final int ALLOC_SIZE = ELEM_SIZE * CARRIER_SIZE;
56
57 static final Unsafe unsafe = Utils.unsafe;
58
59 ByteBuffer dbb = ByteBuffer.allocateDirect(ALLOC_SIZE).order(ByteOrder.nativeOrder());
60 byte[] arr = new byte[ALLOC_SIZE];
61 @SuppressWarnings("initialization")
62 ByteBuffer hbb = ByteBuffer.wrap(arr).order(ByteOrder.nativeOrder());
63 FloatBuffer hfb = hbb.asFloatBuffer();
64
65
66 @Setup
67 public void setup() {
68 for (int i = 0; i < ELEM_SIZE; i++) {
69 dbb.putFloat(i * 4, i);
70 hbb.putFloat(i * 4, i);
71 }
72 for (int i = 0; i < ELEM_SIZE; i++) {
73 hfb.put(i, i);
74 }
75 }
76
77 @TearDown
78 public void tearDown() {
79 unsafe.invokeCleaner(dbb);
80 arr = null;
81 hbb = null;
|