]>
Commit | Line | Data |
---|---|---|
1d09f67e TL |
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; | |
19 | ||
20 | import java.util.concurrent.TimeUnit; | |
21 | ||
22 | import org.apache.arrow.memory.BufferAllocator; | |
23 | import org.apache.arrow.memory.RootAllocator; | |
24 | import org.apache.arrow.vector.ipc.message.ArrowRecordBatch; | |
25 | import org.openjdk.jmh.annotations.Benchmark; | |
26 | import org.openjdk.jmh.annotations.BenchmarkMode; | |
27 | import org.openjdk.jmh.annotations.Level; | |
28 | import org.openjdk.jmh.annotations.Mode; | |
29 | import org.openjdk.jmh.annotations.OutputTimeUnit; | |
30 | import org.openjdk.jmh.annotations.Scope; | |
31 | import org.openjdk.jmh.annotations.Setup; | |
32 | import org.openjdk.jmh.annotations.State; | |
33 | import org.openjdk.jmh.annotations.TearDown; | |
34 | import org.openjdk.jmh.runner.Runner; | |
35 | import org.openjdk.jmh.runner.RunnerException; | |
36 | import org.openjdk.jmh.runner.options.Options; | |
37 | import org.openjdk.jmh.runner.options.OptionsBuilder; | |
38 | ||
39 | /** | |
40 | * Benchmarks for {@link VectorUnloader}. | |
41 | */ | |
42 | @State(Scope.Benchmark) | |
43 | public class VectorUnloaderBenchmark { | |
44 | ||
45 | private static final int ALLOCATOR_CAPACITY = 1024 * 1024; | |
46 | ||
47 | private static final int VECTOR_COUNT = 10; | |
48 | ||
49 | private BufferAllocator allocator; | |
50 | ||
51 | private VarCharVector [] vectors; | |
52 | ||
53 | private VectorUnloader unloader; | |
54 | ||
55 | private ArrowRecordBatch recordBatch; | |
56 | ||
57 | /** | |
58 | * Setup benchmarks. | |
59 | */ | |
60 | @Setup(Level.Trial) | |
61 | public void prepare() { | |
62 | allocator = new RootAllocator(ALLOCATOR_CAPACITY); | |
63 | } | |
64 | ||
65 | @Setup(Level.Invocation) | |
66 | public void prepareInvoke() { | |
67 | vectors = new VarCharVector[VECTOR_COUNT]; | |
68 | for (int i = 0; i < VECTOR_COUNT; i++) { | |
69 | vectors[i] = new VarCharVector("vector", allocator); | |
70 | vectors[i].allocateNew(100, 10); | |
71 | } | |
72 | ||
73 | unloader = new VectorUnloader(VectorSchemaRoot.of(vectors)); | |
74 | } | |
75 | ||
76 | @TearDown(Level.Invocation) | |
77 | public void tearDownInvoke() { | |
78 | if (recordBatch != null) { | |
79 | recordBatch.close(); | |
80 | } | |
81 | for (int i = 0; i < VECTOR_COUNT; i++) { | |
82 | vectors[i].close(); | |
83 | } | |
84 | } | |
85 | ||
86 | /** | |
87 | * Tear down benchmarks. | |
88 | */ | |
89 | @TearDown(Level.Trial) | |
90 | public void tearDown() { | |
91 | allocator.close(); | |
92 | } | |
93 | ||
94 | @Benchmark | |
95 | @BenchmarkMode(Mode.AverageTime) | |
96 | @OutputTimeUnit(TimeUnit.MICROSECONDS) | |
97 | public void unloadBenchmark() { | |
98 | recordBatch = unloader.getRecordBatch(); | |
99 | } | |
100 | ||
101 | public static void main(String[] args) throws RunnerException { | |
102 | Options opt = new OptionsBuilder() | |
103 | .include(VectorUnloaderBenchmark.class.getSimpleName()) | |
104 | .forks(1) | |
105 | .build(); | |
106 | ||
107 | new Runner(opt).run(); | |
108 | } | |
109 | } |