< prev index next >

test/micro/org/openjdk/bench/java/lang/foreign/MemorySegmentVsBits.java

Print this page

 41 import java.lang.invoke.MethodHandles;
 42 import java.lang.invoke.VarHandle;
 43 import java.nio.ByteBuffer;
 44 import java.nio.LongBuffer;
 45 import java.util.concurrent.ThreadLocalRandom;
 46 import java.util.concurrent.TimeUnit;
 47 
 48 import static java.lang.foreign.ValueLayout.*;
 49 import static java.nio.ByteOrder.BIG_ENDIAN;
 50 
 51 /**
 52  * This benchmark creates an array of longs with random contents. The array
 53  * is then copied into a byte array (using big endian) using different
 54  * methods.
 55  */
 56 @BenchmarkMode(Mode.AverageTime)
 57 @Warmup(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS)
 58 @Measurement(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
 59 @State(org.openjdk.jmh.annotations.Scope.Thread)
 60 @OutputTimeUnit(TimeUnit.NANOSECONDS)
 61 @Fork(value = 3, jvmArgsAppend = {"--enable-native-access=ALL-UNNAMED", "--enable-preview"})
 62 public class MemorySegmentVsBits {
 63 
 64     public static final VarHandle LONG_ARRAY_VH = MethodHandles.byteArrayViewVarHandle(long[].class, BIG_ENDIAN);
 65 
 66     Arena arena = Arena.ofConfined();
 67 
 68     @Param({"1", "2", "16", "64", "256"})
 69     public int size;
 70     private long[] longs;
 71     private byte[] bytes;
 72 
 73     private ByteBuffer byteBuffer;
 74     private LongBuffer longBuffer;
 75     private MemorySegment segment;
 76     private MemorySegment nativeSegment;
 77 
 78     private static final ValueLayout.OfLong OF_LONG = (JAVA_LONG.order() != BIG_ENDIAN)
 79             ? JAVA_LONG.withOrder(BIG_ENDIAN)
 80             : JAVA_LONG;
 81 

 41 import java.lang.invoke.MethodHandles;
 42 import java.lang.invoke.VarHandle;
 43 import java.nio.ByteBuffer;
 44 import java.nio.LongBuffer;
 45 import java.util.concurrent.ThreadLocalRandom;
 46 import java.util.concurrent.TimeUnit;
 47 
 48 import static java.lang.foreign.ValueLayout.*;
 49 import static java.nio.ByteOrder.BIG_ENDIAN;
 50 
 51 /**
 52  * This benchmark creates an array of longs with random contents. The array
 53  * is then copied into a byte array (using big endian) using different
 54  * methods.
 55  */
 56 @BenchmarkMode(Mode.AverageTime)
 57 @Warmup(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS)
 58 @Measurement(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
 59 @State(org.openjdk.jmh.annotations.Scope.Thread)
 60 @OutputTimeUnit(TimeUnit.NANOSECONDS)
 61 @Fork(value = 3, jvmArgsAppend = {"--enable-native-access=ALL-UNNAMED"})
 62 public class MemorySegmentVsBits {
 63 
 64     public static final VarHandle LONG_ARRAY_VH = MethodHandles.byteArrayViewVarHandle(long[].class, BIG_ENDIAN);
 65 
 66     Arena arena = Arena.ofConfined();
 67 
 68     @Param({"1", "2", "16", "64", "256"})
 69     public int size;
 70     private long[] longs;
 71     private byte[] bytes;
 72 
 73     private ByteBuffer byteBuffer;
 74     private LongBuffer longBuffer;
 75     private MemorySegment segment;
 76     private MemorySegment nativeSegment;
 77 
 78     private static final ValueLayout.OfLong OF_LONG = (JAVA_LONG.order() != BIG_ENDIAN)
 79             ? JAVA_LONG.withOrder(BIG_ENDIAN)
 80             : JAVA_LONG;
 81 
< prev index next >