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
.vector
.ipc
.message
;
20 import java
.util
.ArrayList
;
21 import java
.util
.List
;
22 import java
.util
.concurrent
.TimeUnit
;
24 import org
.apache
.arrow
.memory
.BufferAllocator
;
25 import org
.apache
.arrow
.memory
.RootAllocator
;
26 import org
.apache
.arrow
.vector
.VarCharVector
;
27 import org
.openjdk
.jmh
.annotations
.Benchmark
;
28 import org
.openjdk
.jmh
.annotations
.BenchmarkMode
;
29 import org
.openjdk
.jmh
.annotations
.Mode
;
30 import org
.openjdk
.jmh
.annotations
.OutputTimeUnit
;
31 import org
.openjdk
.jmh
.annotations
.Scope
;
32 import org
.openjdk
.jmh
.annotations
.Setup
;
33 import org
.openjdk
.jmh
.annotations
.State
;
34 import org
.openjdk
.jmh
.annotations
.TearDown
;
35 import org
.openjdk
.jmh
.runner
.Runner
;
36 import org
.openjdk
.jmh
.runner
.RunnerException
;
37 import org
.openjdk
.jmh
.runner
.options
.Options
;
38 import org
.openjdk
.jmh
.runner
.options
.OptionsBuilder
;
41 * Benchmarks for {@link ArrowRecordBatch}.
43 @State(Scope
.Benchmark
)
44 public class ArrowRecordBatchBenchmarks
{
46 private static final int VECTOR_CAPACITY
= 16 * 1024;
48 private static final int VECTOR_LENGTH
= 1024;
50 private static final int ALLOCATOR_CAPACITY
= 1024 * 1024;
52 private BufferAllocator allocator
;
54 private VarCharVector vector
;
56 private List
<ArrowFieldNode
> nodes
;
62 public void prepare() {
63 allocator
= new RootAllocator(ALLOCATOR_CAPACITY
);
64 vector
= new VarCharVector("vector", allocator
);
65 vector
.allocateNew(VECTOR_CAPACITY
, VECTOR_LENGTH
);
67 nodes
= new ArrayList
<>();
68 nodes
.add(new ArrowFieldNode(VECTOR_LENGTH
, 0));
69 nodes
.add(new ArrowFieldNode(VECTOR_LENGTH
, 0));
73 * Tear down benchmarks.
76 public void tearDown() {
82 @BenchmarkMode(Mode
.AverageTime
)
83 @OutputTimeUnit(TimeUnit
.NANOSECONDS
)
84 public long createAndGetLength() {
85 try (ArrowRecordBatch batch
= new ArrowRecordBatch(VECTOR_LENGTH
, nodes
, vector
.getFieldBuffers())) {
86 return batch
.computeBodyLength();
90 public static void main(String
[] args
) throws RunnerException
{
91 Options opt
= new OptionsBuilder()
92 .include(ArrowRecordBatchBenchmarks
.class.getSimpleName())
96 new Runner(opt
).run();