]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/java/performance/src/test/java/org/apache/arrow/vector/ipc/message/ArrowRecordBatchBenchmarks.java
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / java / performance / src / test / java / org / apache / arrow / vector / ipc / message / ArrowRecordBatchBenchmarks.java
1 /*
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
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
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.
16 */
17
18 package org.apache.arrow.vector.ipc.message;
19
20 import java.util.ArrayList;
21 import java.util.List;
22 import java.util.concurrent.TimeUnit;
23
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;
39
40 /**
41 * Benchmarks for {@link ArrowRecordBatch}.
42 */
43 @State(Scope.Benchmark)
44 public class ArrowRecordBatchBenchmarks {
45
46 private static final int VECTOR_CAPACITY = 16 * 1024;
47
48 private static final int VECTOR_LENGTH = 1024;
49
50 private static final int ALLOCATOR_CAPACITY = 1024 * 1024;
51
52 private BufferAllocator allocator;
53
54 private VarCharVector vector;
55
56 private List<ArrowFieldNode> nodes;
57
58 /**
59 * Setup benchmarks.
60 */
61 @Setup
62 public void prepare() {
63 allocator = new RootAllocator(ALLOCATOR_CAPACITY);
64 vector = new VarCharVector("vector", allocator);
65 vector.allocateNew(VECTOR_CAPACITY, VECTOR_LENGTH);
66
67 nodes = new ArrayList<>();
68 nodes.add(new ArrowFieldNode(VECTOR_LENGTH, 0));
69 nodes.add(new ArrowFieldNode(VECTOR_LENGTH, 0));
70 }
71
72 /**
73 * Tear down benchmarks.
74 */
75 @TearDown
76 public void tearDown() {
77 vector.close();
78 allocator.close();
79 }
80
81 @Benchmark
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();
87 }
88 }
89
90 public static void main(String [] args) throws RunnerException {
91 Options opt = new OptionsBuilder()
92 .include(ArrowRecordBatchBenchmarks.class.getSimpleName())
93 .forks(1)
94 .build();
95
96 new Runner(opt).run();
97 }
98 }