< prev index next >

test/micro/org/openjdk/bench/java/nio/StringCharBufferBulkTransfer.java

Print this page

28 import org.openjdk.jmh.annotations.Benchmark;
29 import org.openjdk.jmh.annotations.Fork;
30 import org.openjdk.jmh.annotations.Measurement;
31 import org.openjdk.jmh.annotations.Scope;
32 import org.openjdk.jmh.annotations.State;
33 import org.openjdk.jmh.annotations.Warmup;
34 
35 /**
36  * Benchmark for bulk get methods of a {@code CharBuffer} created from a
37  * {@code CharSequence}.
38  */
39 
40 @Warmup(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS)
41 @Measurement(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
42 @State(Scope.Benchmark)
43 @Fork(1)
44 public class StringCharBufferBulkTransfer {
45     private static final int LENGTH = 16384;
46 
47     char[] buf = new char[LENGTH];

48     CharBuffer cb = CharBuffer.wrap(new String(buf));
49     char[] dst = new char[LENGTH];
50     CharBuffer cbw = CharBuffer.allocate(LENGTH);
51 
52     @Benchmark
53     public void absoluteBulkGet() {
54         cb.get(0, dst, 0, dst.length);
55     }
56 
57     @Benchmark
58     public void relativeBulkGet() {
59         cb.get(dst, 0, dst.length);
60         cb.position(0);
61     }
62 
63     @Benchmark
64     public void getChars() {
65         cb.getChars(0, LENGTH, dst, 0);
66     }
67 

28 import org.openjdk.jmh.annotations.Benchmark;
29 import org.openjdk.jmh.annotations.Fork;
30 import org.openjdk.jmh.annotations.Measurement;
31 import org.openjdk.jmh.annotations.Scope;
32 import org.openjdk.jmh.annotations.State;
33 import org.openjdk.jmh.annotations.Warmup;
34 
35 /**
36  * Benchmark for bulk get methods of a {@code CharBuffer} created from a
37  * {@code CharSequence}.
38  */
39 
40 @Warmup(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS)
41 @Measurement(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
42 @State(Scope.Benchmark)
43 @Fork(1)
44 public class StringCharBufferBulkTransfer {
45     private static final int LENGTH = 16384;
46 
47     char[] buf = new char[LENGTH];
48     @SuppressWarnings("initialization")
49     CharBuffer cb = CharBuffer.wrap(new String(buf));
50     char[] dst = new char[LENGTH];
51     CharBuffer cbw = CharBuffer.allocate(LENGTH);
52 
53     @Benchmark
54     public void absoluteBulkGet() {
55         cb.get(0, dst, 0, dst.length);
56     }
57 
58     @Benchmark
59     public void relativeBulkGet() {
60         cb.get(dst, 0, dst.length);
61         cb.position(0);
62     }
63 
64     @Benchmark
65     public void getChars() {
66         cb.getChars(0, LENGTH, dst, 0);
67     }
68 
< prev index next >