Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/micro/org/openjdk/bench/java/nio/ByteBuffers.java
41161 views
1
/*
2
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
package org.openjdk.bench.java.nio;
24
25
import org.openjdk.jmh.annotations.Benchmark;
26
import org.openjdk.jmh.annotations.BenchmarkMode;
27
import org.openjdk.jmh.annotations.Fork;
28
import org.openjdk.jmh.annotations.Measurement;
29
import org.openjdk.jmh.annotations.Mode;
30
import org.openjdk.jmh.annotations.OutputTimeUnit;
31
import org.openjdk.jmh.annotations.Param;
32
import org.openjdk.jmh.annotations.Scope;
33
import org.openjdk.jmh.annotations.Setup;
34
import org.openjdk.jmh.annotations.State;
35
import org.openjdk.jmh.annotations.Warmup;
36
import java.nio.*;
37
import java.util.concurrent.TimeUnit;
38
import static java.nio.ByteOrder.*;
39
40
/**
41
* Benchmark for memory access operations on java.nio.Buffer ( and its views )
42
*
43
* A large number of variants are covered. The individual benchmarks conform to
44
* the following convention:
45
* test(Direct|Heap)(Bulk|Loop)(Get|Put)(Byte|Char|Short|Int|Long|Float|Double)(Swap)?(RO)?
46
*
47
* This allows to easily run a subset of particular interest. For example:
48
* Direct only :- "org.openjdk.bench.java.nio.ByteBuffers.testDirect.*"
49
* Bulk only :- "org.openjdk.bench.java.nio.ByteBuffers.test.*Bulk.*"
50
* Loop Put Swapped Views: -
51
* test(Direct|Heap)(Loop)(Put)Byte(View)+(Swap)+"
52
*/
53
@BenchmarkMode(Mode.AverageTime)
54
@Warmup(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS)
55
@Measurement(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
56
@OutputTimeUnit(TimeUnit.NANOSECONDS)
57
@State(Scope.Thread)
58
@Fork(3)
59
public class ByteBuffers {
60
61
static final int CARRIER_BYTE_WIDTH = 1;
62
63
@Param({"16", "1024", "131072"})
64
private int size;
65
66
public byte byteValue;
67
public char charValue;
68
public short shortValue;
69
public int intValue;
70
public long longValue;
71
public float floatValue;
72
public double doubleValue;
73
public byte[] byteArray;
74
75
public ByteBuffer heapByteBuffer;
76
public ByteBuffer heapByteBufferRO;
77
public ByteBuffer directByteBuffer;
78
public ByteBuffer directByteBufferRO;
79
public ByteBuffer heapByteBufferSwap;
80
public ByteBuffer heapByteBufferSwapRO;
81
public ByteBuffer directByteBufferSwap;
82
public ByteBuffer directByteBufferSwapRO;
83
84
@Setup
85
public void setup() {
86
byteArray = new byte[size / CARRIER_BYTE_WIDTH];
87
88
// explicitly allocated heap carrier buffer
89
heapByteBuffer = ByteBuffer.allocate(size / CARRIER_BYTE_WIDTH);
90
heapByteBufferRO = ByteBuffer.allocate(size / CARRIER_BYTE_WIDTH).asReadOnlyBuffer();
91
92
heapByteBufferSwap = ByteBuffer.allocate(size / CARRIER_BYTE_WIDTH).order(LITTLE_ENDIAN);
93
heapByteBufferSwapRO = ByteBuffer.allocate(size / CARRIER_BYTE_WIDTH).order(LITTLE_ENDIAN).asReadOnlyBuffer();
94
directByteBuffer = ByteBuffer.allocateDirect(size / CARRIER_BYTE_WIDTH);
95
directByteBufferRO = ByteBuffer.allocateDirect(size / CARRIER_BYTE_WIDTH).asReadOnlyBuffer();
96
directByteBufferSwap = ByteBuffer.allocateDirect(size / CARRIER_BYTE_WIDTH).order(LITTLE_ENDIAN);
97
directByteBufferSwapRO = ByteBuffer.allocateDirect(size / CARRIER_BYTE_WIDTH).order(LITTLE_ENDIAN).asReadOnlyBuffer();
98
}
99
100
101
// -- Heap___
102
103
@Benchmark
104
public byte[] testHeapBulkPutByte() {
105
heapByteBuffer.put(0, byteArray);
106
return byteArray;
107
}
108
109
@Benchmark
110
public byte[] testHeapBulkGetByte() {
111
heapByteBuffer.get(0, byteArray);
112
return byteArray;
113
}
114
115
// -- Heap_Byte_Swap_RO
116
117
@Benchmark
118
public int testHeapLoopGetByteSwapRO() {
119
int r = 0;
120
for (int i = 0; i < heapByteBufferSwapRO.capacity(); i+=1) {
121
r += heapByteBufferSwapRO.get(i);
122
}
123
return r;
124
}
125
126
// -- Heap_Byte_Swap_
127
128
@Benchmark
129
public void testHeapLoopPutByteSwap() {
130
for (int i = 0; i < heapByteBufferSwap.capacity(); i+=1) {
131
heapByteBufferSwap.put(i, byteValue);
132
}
133
}
134
135
@Benchmark
136
public int testHeapLoopGetByteSwap() {
137
int r = 0;
138
for (int i = 0; i < heapByteBufferSwap.capacity(); i+=1) {
139
r += heapByteBufferSwap.get(i);
140
}
141
return r;
142
}
143
144
// -- Heap_Byte__RO
145
146
@Benchmark
147
public int testHeapLoopGetByteRO() {
148
int r = 0;
149
for (int i = 0; i < heapByteBufferRO.capacity(); i+=1) {
150
r += heapByteBufferRO.get(i);
151
}
152
return r;
153
}
154
155
// -- Heap_Byte__
156
157
@Benchmark
158
public void testHeapLoopPutByte() {
159
for (int i = 0; i < heapByteBuffer.capacity(); i+=1) {
160
heapByteBuffer.put(i, byteValue);
161
}
162
}
163
164
@Benchmark
165
public int testHeapLoopGetByte() {
166
int r = 0;
167
for (int i = 0; i < heapByteBuffer.capacity(); i+=1) {
168
r += heapByteBuffer.get(i);
169
}
170
return r;
171
}
172
173
// -- Direct_Byte_Swap_RO
174
175
@Benchmark
176
public int testDirectLoopGetByteSwapRO() {
177
int r = 0;
178
for (int i = 0; i < directByteBufferSwapRO.capacity(); i+=1) {
179
r += directByteBufferSwapRO.get(i);
180
}
181
return r;
182
}
183
184
// -- Direct_Byte_Swap_
185
186
@Benchmark
187
public void testDirectLoopPutByteSwap() {
188
for (int i = 0; i < directByteBufferSwap.capacity(); i+=1) {
189
directByteBufferSwap.put(i, byteValue);
190
}
191
}
192
193
@Benchmark
194
public int testDirectLoopGetByteSwap() {
195
int r = 0;
196
for (int i = 0; i < directByteBufferSwap.capacity(); i+=1) {
197
r += directByteBufferSwap.get(i);
198
}
199
return r;
200
}
201
202
// -- Direct_Byte__RO
203
204
@Benchmark
205
public int testDirectLoopGetByteRO() {
206
int r = 0;
207
for (int i = 0; i < directByteBufferRO.capacity(); i+=1) {
208
r += directByteBufferRO.get(i);
209
}
210
return r;
211
}
212
213
// -- Direct_Byte__
214
215
@Benchmark
216
public void testDirectLoopPutByte() {
217
for (int i = 0; i < directByteBuffer.capacity(); i+=1) {
218
directByteBuffer.put(i, byteValue);
219
}
220
}
221
222
@Benchmark
223
public int testDirectLoopGetByte() {
224
int r = 0;
225
for (int i = 0; i < directByteBuffer.capacity(); i+=1) {
226
r += directByteBuffer.get(i);
227
}
228
return r;
229
}
230
231
// -- Heap_Char_Swap_RO
232
233
@Benchmark
234
public int testHeapLoopGetCharSwapRO() {
235
int r = 0;
236
for (int i = 0; i < heapByteBufferSwapRO.capacity(); i+=2) {
237
r += heapByteBufferSwapRO.getChar(i);
238
}
239
return r;
240
}
241
242
// -- Heap_Char_Swap_
243
244
@Benchmark
245
public void testHeapLoopPutCharSwap() {
246
for (int i = 0; i < heapByteBufferSwap.capacity(); i+=2) {
247
heapByteBufferSwap.putChar(i, charValue);
248
}
249
}
250
251
@Benchmark
252
public int testHeapLoopGetCharSwap() {
253
int r = 0;
254
for (int i = 0; i < heapByteBufferSwap.capacity(); i+=2) {
255
r += heapByteBufferSwap.getChar(i);
256
}
257
return r;
258
}
259
260
// -- Heap_Char__RO
261
262
@Benchmark
263
public int testHeapLoopGetCharRO() {
264
int r = 0;
265
for (int i = 0; i < heapByteBufferRO.capacity(); i+=2) {
266
r += heapByteBufferRO.getChar(i);
267
}
268
return r;
269
}
270
271
// -- Heap_Char__
272
273
@Benchmark
274
public void testHeapLoopPutChar() {
275
for (int i = 0; i < heapByteBuffer.capacity(); i+=2) {
276
heapByteBuffer.putChar(i, charValue);
277
}
278
}
279
280
@Benchmark
281
public int testHeapLoopGetChar() {
282
int r = 0;
283
for (int i = 0; i < heapByteBuffer.capacity(); i+=2) {
284
r += heapByteBuffer.getChar(i);
285
}
286
return r;
287
}
288
289
// -- Direct_Char_Swap_RO
290
291
@Benchmark
292
public int testDirectLoopGetCharSwapRO() {
293
int r = 0;
294
for (int i = 0; i < directByteBufferSwapRO.capacity(); i+=2) {
295
r += directByteBufferSwapRO.getChar(i);
296
}
297
return r;
298
}
299
300
// -- Direct_Char_Swap_
301
302
@Benchmark
303
public void testDirectLoopPutCharSwap() {
304
for (int i = 0; i < directByteBufferSwap.capacity(); i+=2) {
305
directByteBufferSwap.putChar(i, charValue);
306
}
307
}
308
309
@Benchmark
310
public int testDirectLoopGetCharSwap() {
311
int r = 0;
312
for (int i = 0; i < directByteBufferSwap.capacity(); i+=2) {
313
r += directByteBufferSwap.getChar(i);
314
}
315
return r;
316
}
317
318
// -- Direct_Char__RO
319
320
@Benchmark
321
public int testDirectLoopGetCharRO() {
322
int r = 0;
323
for (int i = 0; i < directByteBufferRO.capacity(); i+=2) {
324
r += directByteBufferRO.getChar(i);
325
}
326
return r;
327
}
328
329
// -- Direct_Char__
330
331
@Benchmark
332
public void testDirectLoopPutChar() {
333
for (int i = 0; i < directByteBuffer.capacity(); i+=2) {
334
directByteBuffer.putChar(i, charValue);
335
}
336
}
337
338
@Benchmark
339
public int testDirectLoopGetChar() {
340
int r = 0;
341
for (int i = 0; i < directByteBuffer.capacity(); i+=2) {
342
r += directByteBuffer.getChar(i);
343
}
344
return r;
345
}
346
347
// -- Heap_Short_Swap_RO
348
349
@Benchmark
350
public int testHeapLoopGetShortSwapRO() {
351
int r = 0;
352
for (int i = 0; i < heapByteBufferSwapRO.capacity(); i+=2) {
353
r += heapByteBufferSwapRO.getShort(i);
354
}
355
return r;
356
}
357
358
// -- Heap_Short_Swap_
359
360
@Benchmark
361
public void testHeapLoopPutShortSwap() {
362
for (int i = 0; i < heapByteBufferSwap.capacity(); i+=2) {
363
heapByteBufferSwap.putShort(i, shortValue);
364
}
365
}
366
367
@Benchmark
368
public int testHeapLoopGetShortSwap() {
369
int r = 0;
370
for (int i = 0; i < heapByteBufferSwap.capacity(); i+=2) {
371
r += heapByteBufferSwap.getShort(i);
372
}
373
return r;
374
}
375
376
// -- Heap_Short__RO
377
378
@Benchmark
379
public int testHeapLoopGetShortRO() {
380
int r = 0;
381
for (int i = 0; i < heapByteBufferRO.capacity(); i+=2) {
382
r += heapByteBufferRO.getShort(i);
383
}
384
return r;
385
}
386
387
// -- Heap_Short__
388
389
@Benchmark
390
public void testHeapLoopPutShort() {
391
for (int i = 0; i < heapByteBuffer.capacity(); i+=2) {
392
heapByteBuffer.putShort(i, shortValue);
393
}
394
}
395
396
@Benchmark
397
public int testHeapLoopGetShort() {
398
int r = 0;
399
for (int i = 0; i < heapByteBuffer.capacity(); i+=2) {
400
r += heapByteBuffer.getShort(i);
401
}
402
return r;
403
}
404
405
// -- Direct_Short_Swap_RO
406
407
@Benchmark
408
public int testDirectLoopGetShortSwapRO() {
409
int r = 0;
410
for (int i = 0; i < directByteBufferSwapRO.capacity(); i+=2) {
411
r += directByteBufferSwapRO.getShort(i);
412
}
413
return r;
414
}
415
416
// -- Direct_Short_Swap_
417
418
@Benchmark
419
public void testDirectLoopPutShortSwap() {
420
for (int i = 0; i < directByteBufferSwap.capacity(); i+=2) {
421
directByteBufferSwap.putShort(i, shortValue);
422
}
423
}
424
425
@Benchmark
426
public int testDirectLoopGetShortSwap() {
427
int r = 0;
428
for (int i = 0; i < directByteBufferSwap.capacity(); i+=2) {
429
r += directByteBufferSwap.getShort(i);
430
}
431
return r;
432
}
433
434
// -- Direct_Short__RO
435
436
@Benchmark
437
public int testDirectLoopGetShortRO() {
438
int r = 0;
439
for (int i = 0; i < directByteBufferRO.capacity(); i+=2) {
440
r += directByteBufferRO.getShort(i);
441
}
442
return r;
443
}
444
445
// -- Direct_Short__
446
447
@Benchmark
448
public void testDirectLoopPutShort() {
449
for (int i = 0; i < directByteBuffer.capacity(); i+=2) {
450
directByteBuffer.putShort(i, shortValue);
451
}
452
}
453
454
@Benchmark
455
public int testDirectLoopGetShort() {
456
int r = 0;
457
for (int i = 0; i < directByteBuffer.capacity(); i+=2) {
458
r += directByteBuffer.getShort(i);
459
}
460
return r;
461
}
462
463
// -- Heap_Int_Swap_RO
464
465
@Benchmark
466
public int testHeapLoopGetIntSwapRO() {
467
int r = 0;
468
for (int i = 0; i < heapByteBufferSwapRO.capacity(); i+=4) {
469
r += heapByteBufferSwapRO.getInt(i);
470
}
471
return r;
472
}
473
474
// -- Heap_Int_Swap_
475
476
@Benchmark
477
public void testHeapLoopPutIntSwap() {
478
for (int i = 0; i < heapByteBufferSwap.capacity(); i+=4) {
479
heapByteBufferSwap.putInt(i, intValue);
480
}
481
}
482
483
@Benchmark
484
public int testHeapLoopGetIntSwap() {
485
int r = 0;
486
for (int i = 0; i < heapByteBufferSwap.capacity(); i+=4) {
487
r += heapByteBufferSwap.getInt(i);
488
}
489
return r;
490
}
491
492
// -- Heap_Int__RO
493
494
@Benchmark
495
public int testHeapLoopGetIntRO() {
496
int r = 0;
497
for (int i = 0; i < heapByteBufferRO.capacity(); i+=4) {
498
r += heapByteBufferRO.getInt(i);
499
}
500
return r;
501
}
502
503
// -- Heap_Int__
504
505
@Benchmark
506
public void testHeapLoopPutInt() {
507
for (int i = 0; i < heapByteBuffer.capacity(); i+=4) {
508
heapByteBuffer.putInt(i, intValue);
509
}
510
}
511
512
@Benchmark
513
public int testHeapLoopGetInt() {
514
int r = 0;
515
for (int i = 0; i < heapByteBuffer.capacity(); i+=4) {
516
r += heapByteBuffer.getInt(i);
517
}
518
return r;
519
}
520
521
// -- Direct_Int_Swap_RO
522
523
@Benchmark
524
public int testDirectLoopGetIntSwapRO() {
525
int r = 0;
526
for (int i = 0; i < directByteBufferSwapRO.capacity(); i+=4) {
527
r += directByteBufferSwapRO.getInt(i);
528
}
529
return r;
530
}
531
532
// -- Direct_Int_Swap_
533
534
@Benchmark
535
public void testDirectLoopPutIntSwap() {
536
for (int i = 0; i < directByteBufferSwap.capacity(); i+=4) {
537
directByteBufferSwap.putInt(i, intValue);
538
}
539
}
540
541
@Benchmark
542
public int testDirectLoopGetIntSwap() {
543
int r = 0;
544
for (int i = 0; i < directByteBufferSwap.capacity(); i+=4) {
545
r += directByteBufferSwap.getInt(i);
546
}
547
return r;
548
}
549
550
// -- Direct_Int__RO
551
552
@Benchmark
553
public int testDirectLoopGetIntRO() {
554
int r = 0;
555
for (int i = 0; i < directByteBufferRO.capacity(); i+=4) {
556
r += directByteBufferRO.getInt(i);
557
}
558
return r;
559
}
560
561
// -- Direct_Int__
562
563
@Benchmark
564
public void testDirectLoopPutInt() {
565
for (int i = 0; i < directByteBuffer.capacity(); i+=4) {
566
directByteBuffer.putInt(i, intValue);
567
}
568
}
569
570
@Benchmark
571
public int testDirectLoopGetInt() {
572
int r = 0;
573
for (int i = 0; i < directByteBuffer.capacity(); i+=4) {
574
r += directByteBuffer.getInt(i);
575
}
576
return r;
577
}
578
579
// -- Heap_Long_Swap_RO
580
581
@Benchmark
582
public int testHeapLoopGetLongSwapRO() {
583
int r = 0;
584
for (int i = 0; i < heapByteBufferSwapRO.capacity(); i+=8) {
585
r += heapByteBufferSwapRO.getLong(i);
586
}
587
return r;
588
}
589
590
// -- Heap_Long_Swap_
591
592
@Benchmark
593
public void testHeapLoopPutLongSwap() {
594
for (int i = 0; i < heapByteBufferSwap.capacity(); i+=8) {
595
heapByteBufferSwap.putLong(i, longValue);
596
}
597
}
598
599
@Benchmark
600
public int testHeapLoopGetLongSwap() {
601
int r = 0;
602
for (int i = 0; i < heapByteBufferSwap.capacity(); i+=8) {
603
r += heapByteBufferSwap.getLong(i);
604
}
605
return r;
606
}
607
608
// -- Heap_Long__RO
609
610
@Benchmark
611
public int testHeapLoopGetLongRO() {
612
int r = 0;
613
for (int i = 0; i < heapByteBufferRO.capacity(); i+=8) {
614
r += heapByteBufferRO.getLong(i);
615
}
616
return r;
617
}
618
619
// -- Heap_Long__
620
621
@Benchmark
622
public void testHeapLoopPutLong() {
623
for (int i = 0; i < heapByteBuffer.capacity(); i+=8) {
624
heapByteBuffer.putLong(i, longValue);
625
}
626
}
627
628
@Benchmark
629
public int testHeapLoopGetLong() {
630
int r = 0;
631
for (int i = 0; i < heapByteBuffer.capacity(); i+=8) {
632
r += heapByteBuffer.getLong(i);
633
}
634
return r;
635
}
636
637
// -- Direct_Long_Swap_RO
638
639
@Benchmark
640
public int testDirectLoopGetLongSwapRO() {
641
int r = 0;
642
for (int i = 0; i < directByteBufferSwapRO.capacity(); i+=8) {
643
r += directByteBufferSwapRO.getLong(i);
644
}
645
return r;
646
}
647
648
// -- Direct_Long_Swap_
649
650
@Benchmark
651
public void testDirectLoopPutLongSwap() {
652
for (int i = 0; i < directByteBufferSwap.capacity(); i+=8) {
653
directByteBufferSwap.putLong(i, longValue);
654
}
655
}
656
657
@Benchmark
658
public int testDirectLoopGetLongSwap() {
659
int r = 0;
660
for (int i = 0; i < directByteBufferSwap.capacity(); i+=8) {
661
r += directByteBufferSwap.getLong(i);
662
}
663
return r;
664
}
665
666
// -- Direct_Long__RO
667
668
@Benchmark
669
public int testDirectLoopGetLongRO() {
670
int r = 0;
671
for (int i = 0; i < directByteBufferRO.capacity(); i+=8) {
672
r += directByteBufferRO.getLong(i);
673
}
674
return r;
675
}
676
677
// -- Direct_Long__
678
679
@Benchmark
680
public void testDirectLoopPutLong() {
681
for (int i = 0; i < directByteBuffer.capacity(); i+=8) {
682
directByteBuffer.putLong(i, longValue);
683
}
684
}
685
686
@Benchmark
687
public int testDirectLoopGetLong() {
688
int r = 0;
689
for (int i = 0; i < directByteBuffer.capacity(); i+=8) {
690
r += directByteBuffer.getLong(i);
691
}
692
return r;
693
}
694
695
// -- Heap_Float_Swap_RO
696
697
@Benchmark
698
public int testHeapLoopGetFloatSwapRO() {
699
int r = 0;
700
for (int i = 0; i < heapByteBufferSwapRO.capacity(); i+=4) {
701
r += heapByteBufferSwapRO.getFloat(i);
702
}
703
return r;
704
}
705
706
// -- Heap_Float_Swap_
707
708
@Benchmark
709
public void testHeapLoopPutFloatSwap() {
710
for (int i = 0; i < heapByteBufferSwap.capacity(); i+=4) {
711
heapByteBufferSwap.putFloat(i, floatValue);
712
}
713
}
714
715
@Benchmark
716
public int testHeapLoopGetFloatSwap() {
717
int r = 0;
718
for (int i = 0; i < heapByteBufferSwap.capacity(); i+=4) {
719
r += heapByteBufferSwap.getFloat(i);
720
}
721
return r;
722
}
723
724
// -- Heap_Float__RO
725
726
@Benchmark
727
public int testHeapLoopGetFloatRO() {
728
int r = 0;
729
for (int i = 0; i < heapByteBufferRO.capacity(); i+=4) {
730
r += heapByteBufferRO.getFloat(i);
731
}
732
return r;
733
}
734
735
// -- Heap_Float__
736
737
@Benchmark
738
public void testHeapLoopPutFloat() {
739
for (int i = 0; i < heapByteBuffer.capacity(); i+=4) {
740
heapByteBuffer.putFloat(i, floatValue);
741
}
742
}
743
744
@Benchmark
745
public int testHeapLoopGetFloat() {
746
int r = 0;
747
for (int i = 0; i < heapByteBuffer.capacity(); i+=4) {
748
r += heapByteBuffer.getFloat(i);
749
}
750
return r;
751
}
752
753
// -- Direct_Float_Swap_RO
754
755
@Benchmark
756
public int testDirectLoopGetFloatSwapRO() {
757
int r = 0;
758
for (int i = 0; i < directByteBufferSwapRO.capacity(); i+=4) {
759
r += directByteBufferSwapRO.getFloat(i);
760
}
761
return r;
762
}
763
764
// -- Direct_Float_Swap_
765
766
@Benchmark
767
public void testDirectLoopPutFloatSwap() {
768
for (int i = 0; i < directByteBufferSwap.capacity(); i+=4) {
769
directByteBufferSwap.putFloat(i, floatValue);
770
}
771
}
772
773
@Benchmark
774
public int testDirectLoopGetFloatSwap() {
775
int r = 0;
776
for (int i = 0; i < directByteBufferSwap.capacity(); i+=4) {
777
r += directByteBufferSwap.getFloat(i);
778
}
779
return r;
780
}
781
782
// -- Direct_Float__RO
783
784
@Benchmark
785
public int testDirectLoopGetFloatRO() {
786
int r = 0;
787
for (int i = 0; i < directByteBufferRO.capacity(); i+=4) {
788
r += directByteBufferRO.getFloat(i);
789
}
790
return r;
791
}
792
793
// -- Direct_Float__
794
795
@Benchmark
796
public void testDirectLoopPutFloat() {
797
for (int i = 0; i < directByteBuffer.capacity(); i+=4) {
798
directByteBuffer.putFloat(i, floatValue);
799
}
800
}
801
802
@Benchmark
803
public int testDirectLoopGetFloat() {
804
int r = 0;
805
for (int i = 0; i < directByteBuffer.capacity(); i+=4) {
806
r += directByteBuffer.getFloat(i);
807
}
808
return r;
809
}
810
811
// -- Heap_Double_Swap_RO
812
813
@Benchmark
814
public int testHeapLoopGetDoubleSwapRO() {
815
int r = 0;
816
for (int i = 0; i < heapByteBufferSwapRO.capacity(); i+=8) {
817
r += heapByteBufferSwapRO.getDouble(i);
818
}
819
return r;
820
}
821
822
// -- Heap_Double_Swap_
823
824
@Benchmark
825
public void testHeapLoopPutDoubleSwap() {
826
for (int i = 0; i < heapByteBufferSwap.capacity(); i+=8) {
827
heapByteBufferSwap.putDouble(i, doubleValue);
828
}
829
}
830
831
@Benchmark
832
public int testHeapLoopGetDoubleSwap() {
833
int r = 0;
834
for (int i = 0; i < heapByteBufferSwap.capacity(); i+=8) {
835
r += heapByteBufferSwap.getDouble(i);
836
}
837
return r;
838
}
839
840
// -- Heap_Double__RO
841
842
@Benchmark
843
public int testHeapLoopGetDoubleRO() {
844
int r = 0;
845
for (int i = 0; i < heapByteBufferRO.capacity(); i+=8) {
846
r += heapByteBufferRO.getDouble(i);
847
}
848
return r;
849
}
850
851
// -- Heap_Double__
852
853
@Benchmark
854
public void testHeapLoopPutDouble() {
855
for (int i = 0; i < heapByteBuffer.capacity(); i+=8) {
856
heapByteBuffer.putDouble(i, doubleValue);
857
}
858
}
859
860
@Benchmark
861
public int testHeapLoopGetDouble() {
862
int r = 0;
863
for (int i = 0; i < heapByteBuffer.capacity(); i+=8) {
864
r += heapByteBuffer.getDouble(i);
865
}
866
return r;
867
}
868
869
// -- Direct_Double_Swap_RO
870
871
@Benchmark
872
public int testDirectLoopGetDoubleSwapRO() {
873
int r = 0;
874
for (int i = 0; i < directByteBufferSwapRO.capacity(); i+=8) {
875
r += directByteBufferSwapRO.getDouble(i);
876
}
877
return r;
878
}
879
880
// -- Direct_Double_Swap_
881
882
@Benchmark
883
public void testDirectLoopPutDoubleSwap() {
884
for (int i = 0; i < directByteBufferSwap.capacity(); i+=8) {
885
directByteBufferSwap.putDouble(i, doubleValue);
886
}
887
}
888
889
@Benchmark
890
public int testDirectLoopGetDoubleSwap() {
891
int r = 0;
892
for (int i = 0; i < directByteBufferSwap.capacity(); i+=8) {
893
r += directByteBufferSwap.getDouble(i);
894
}
895
return r;
896
}
897
898
// -- Direct_Double__RO
899
900
@Benchmark
901
public int testDirectLoopGetDoubleRO() {
902
int r = 0;
903
for (int i = 0; i < directByteBufferRO.capacity(); i+=8) {
904
r += directByteBufferRO.getDouble(i);
905
}
906
return r;
907
}
908
909
// -- Direct_Double__
910
911
@Benchmark
912
public void testDirectLoopPutDouble() {
913
for (int i = 0; i < directByteBuffer.capacity(); i+=8) {
914
directByteBuffer.putDouble(i, doubleValue);
915
}
916
}
917
918
@Benchmark
919
public int testDirectLoopGetDouble() {
920
int r = 0;
921
for (int i = 0; i < directByteBuffer.capacity(); i+=8) {
922
r += directByteBuffer.getDouble(i);
923
}
924
return r;
925
}
926
}
927
928