2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package org
.apache
.arrow
.memory
.util
;
20 import java
.util
.concurrent
.TimeUnit
;
22 import org
.apache
.arrow
.memory
.ArrowBuf
;
23 import org
.apache
.arrow
.memory
.BufferAllocator
;
24 import org
.apache
.arrow
.memory
.RootAllocator
;
25 import org
.openjdk
.jmh
.annotations
.Benchmark
;
26 import org
.openjdk
.jmh
.annotations
.BenchmarkMode
;
27 import org
.openjdk
.jmh
.annotations
.Mode
;
28 import org
.openjdk
.jmh
.annotations
.OutputTimeUnit
;
29 import org
.openjdk
.jmh
.annotations
.Scope
;
30 import org
.openjdk
.jmh
.annotations
.Setup
;
31 import org
.openjdk
.jmh
.annotations
.State
;
32 import org
.openjdk
.jmh
.annotations
.TearDown
;
33 import org
.openjdk
.jmh
.runner
.Runner
;
34 import org
.openjdk
.jmh
.runner
.RunnerException
;
35 import org
.openjdk
.jmh
.runner
.options
.Options
;
36 import org
.openjdk
.jmh
.runner
.options
.OptionsBuilder
;
39 * Benchmarks for {@link ArrowBufPointer}.
41 @State(Scope
.Benchmark
)
42 public class ArrowBufPointerBenchmarks
{
44 private static final int BUFFER_CAPACITY
= 1000;
46 private static final int ALLOCATOR_CAPACITY
= 1024 * 1024;
48 private BufferAllocator allocator
;
50 private ArrowBuf buffer1
;
52 private ArrowBuf buffer2
;
54 private ArrowBufPointer pointer1
;
56 private ArrowBufPointer pointer2
;
62 public void prepare() {
63 allocator
= new RootAllocator(ALLOCATOR_CAPACITY
);
64 buffer1
= allocator
.buffer(BUFFER_CAPACITY
);
65 buffer2
= allocator
.buffer(BUFFER_CAPACITY
);
67 for (int i
= 0; i
< BUFFER_CAPACITY
; i
++) {
68 buffer1
.setByte(i
, i
);
69 buffer2
.setByte(i
, i
);
72 // make the last bytes different
73 buffer1
.setByte(BUFFER_CAPACITY
- 1, 12);
74 buffer1
.setByte(BUFFER_CAPACITY
- 1, 123);
76 pointer1
= new ArrowBufPointer(buffer1
, 0, BUFFER_CAPACITY
);
77 pointer2
= new ArrowBufPointer(buffer2
, 0, BUFFER_CAPACITY
);
81 * Tear down benchmarks.
84 public void tearDown() {
91 @BenchmarkMode(Mode
.AverageTime
)
92 @OutputTimeUnit(TimeUnit
.NANOSECONDS
)
93 public int compareBenchmark() {
94 return pointer1
.compareTo(pointer2
);
97 public static void main(String
[] args
) throws RunnerException
{
98 Options opt
= new OptionsBuilder()
99 .include(ArrowBufPointerBenchmarks
.class.getSimpleName())
103 new Runner(opt
).run();