]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/java/performance/src/test/java/org/apache/arrow/memory/util/ArrowBufPointerBenchmarks.java
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / java / performance / src / test / java / org / apache / arrow / memory / util / ArrowBufPointerBenchmarks.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.memory.util;
19
20 import java.util.concurrent.TimeUnit;
21
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;
37
38 /**
39 * Benchmarks for {@link ArrowBufPointer}.
40 */
41 @State(Scope.Benchmark)
42 public class ArrowBufPointerBenchmarks {
43
44 private static final int BUFFER_CAPACITY = 1000;
45
46 private static final int ALLOCATOR_CAPACITY = 1024 * 1024;
47
48 private BufferAllocator allocator;
49
50 private ArrowBuf buffer1;
51
52 private ArrowBuf buffer2;
53
54 private ArrowBufPointer pointer1;
55
56 private ArrowBufPointer pointer2;
57
58 /**
59 * Setup benchmarks.
60 */
61 @Setup
62 public void prepare() {
63 allocator = new RootAllocator(ALLOCATOR_CAPACITY);
64 buffer1 = allocator.buffer(BUFFER_CAPACITY);
65 buffer2 = allocator.buffer(BUFFER_CAPACITY);
66
67 for (int i = 0; i < BUFFER_CAPACITY; i++) {
68 buffer1.setByte(i, i);
69 buffer2.setByte(i, i);
70 }
71
72 // make the last bytes different
73 buffer1.setByte(BUFFER_CAPACITY - 1, 12);
74 buffer1.setByte(BUFFER_CAPACITY - 1, 123);
75
76 pointer1 = new ArrowBufPointer(buffer1, 0, BUFFER_CAPACITY);
77 pointer2 = new ArrowBufPointer(buffer2, 0, BUFFER_CAPACITY);
78 }
79
80 /**
81 * Tear down benchmarks.
82 */
83 @TearDown
84 public void tearDown() {
85 buffer1.close();
86 buffer2.close();
87 allocator.close();
88 }
89
90 @Benchmark
91 @BenchmarkMode(Mode.AverageTime)
92 @OutputTimeUnit(TimeUnit.NANOSECONDS)
93 public int compareBenchmark() {
94 return pointer1.compareTo(pointer2);
95 }
96
97 public static void main(String[] args) throws RunnerException {
98 Options opt = new OptionsBuilder()
99 .include(ArrowBufPointerBenchmarks.class.getSimpleName())
100 .forks(1)
101 .build();
102
103 new Runner(opt).run();
104 }
105 }
106
107