Skip to content

Commit 3dd0311

Browse files
authored
apacheGH-41: Add VariableWidthViewVectorBenchmarks (apache#453)
GitHub Issue: apache#41
1 parent 1bde279 commit 3dd0311

5 files changed

+422
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
package org.apache.arrow.vector;
18+
19+
public class VariableWidthVectorBenchmarkConstants {
20+
public static final String SHORT_VALUE = "InlineValue";
21+
public static final String LONG_VALUE = VariableWidthVectorBenchmarks.class.getName();
22+
}

performance/src/main/java/org/apache/arrow/vector/VariableWidthVectorBenchmarks.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
import org.apache.arrow.vector.holders.NullableVarCharHolder;
2424
import org.openjdk.jmh.annotations.Benchmark;
2525
import org.openjdk.jmh.annotations.BenchmarkMode;
26+
import org.openjdk.jmh.annotations.Level;
2627
import org.openjdk.jmh.annotations.Mode;
2728
import org.openjdk.jmh.annotations.OutputTimeUnit;
29+
import org.openjdk.jmh.annotations.Param;
2830
import org.openjdk.jmh.annotations.Scope;
2931
import org.openjdk.jmh.annotations.Setup;
3032
import org.openjdk.jmh.annotations.State;
@@ -45,15 +47,18 @@ public class VariableWidthVectorBenchmarks {
4547

4648
private static final int ALLOCATOR_CAPACITY = 1024 * 1024;
4749

48-
private static byte[] bytes = VariableWidthVectorBenchmarks.class.getName().getBytes();
50+
private static byte[] bytes = VariableWidthVectorBenchmarkConstants.LONG_VALUE.getBytes();
4951
private ArrowBuf arrowBuff;
5052

5153
private BufferAllocator allocator;
5254

5355
private VarCharVector vector;
5456

57+
@Param({"1", "2", "10", "40"})
58+
private int step;
59+
5560
/** Setup benchmarks. */
56-
@Setup
61+
@Setup(Level.Iteration)
5762
public void prepare() {
5863
allocator = new RootAllocator(ALLOCATOR_CAPACITY);
5964
vector = new VarCharVector("vector", allocator);
@@ -63,7 +68,7 @@ public void prepare() {
6368
}
6469

6570
/** Tear down benchmarks. */
66-
@TearDown
71+
@TearDown(Level.Iteration)
6772
public void tearDown() {
6873
arrowBuff.close();
6974
vector.close();
@@ -87,7 +92,7 @@ public int getValueCapacity() {
8792
@OutputTimeUnit(TimeUnit.MILLISECONDS)
8893
public int setSafeFromArray() {
8994
for (int i = 0; i < 500; ++i) {
90-
vector.setSafe(i * 40, bytes);
95+
vector.setSafe(i * step, bytes);
9196
}
9297
return vector.getBufferSize();
9398
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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+
package org.apache.arrow.vector;
18+
19+
import java.util.concurrent.TimeUnit;
20+
import org.apache.arrow.memory.ArrowBuf;
21+
import org.apache.arrow.memory.BufferAllocator;
22+
import org.apache.arrow.memory.RootAllocator;
23+
import org.apache.arrow.vector.holders.NullableVarCharHolder;
24+
import org.openjdk.jmh.annotations.Benchmark;
25+
import org.openjdk.jmh.annotations.BenchmarkMode;
26+
import org.openjdk.jmh.annotations.Level;
27+
import org.openjdk.jmh.annotations.Mode;
28+
import org.openjdk.jmh.annotations.OutputTimeUnit;
29+
import org.openjdk.jmh.annotations.Param;
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+
/** Benchmarks for {@link BaseVariableWidthVector}. */
40+
@State(Scope.Benchmark)
41+
public class VariableWidthVectorInlineValueBenchmarks {
42+
// checkstyle:off: MissingJavadocMethod
43+
44+
private static final int VECTOR_CAPACITY = 16 * 1024;
45+
46+
private static final int VECTOR_LENGTH = 1024;
47+
48+
private static final int ALLOCATOR_CAPACITY = 1024 * 1024;
49+
50+
private static final byte[] bytes = VariableWidthVectorBenchmarkConstants.SHORT_VALUE.getBytes();
51+
private ArrowBuf arrowBuff;
52+
53+
private BufferAllocator allocator;
54+
55+
private VarCharVector vector;
56+
57+
@Param({"1", "2", "10", "40"})
58+
private int step;
59+
60+
/** Setup benchmarks. */
61+
@Setup(Level.Iteration)
62+
public void prepare() {
63+
allocator = new RootAllocator(ALLOCATOR_CAPACITY);
64+
vector = new VarCharVector("vector", allocator);
65+
vector.allocateNew(VECTOR_CAPACITY, VECTOR_LENGTH);
66+
arrowBuff = allocator.buffer(VECTOR_LENGTH);
67+
arrowBuff.setBytes(0, bytes, 0, bytes.length);
68+
}
69+
70+
/** Tear down benchmarks. */
71+
@TearDown(Level.Iteration)
72+
public void tearDown() {
73+
arrowBuff.close();
74+
vector.close();
75+
allocator.close();
76+
}
77+
78+
/**
79+
* Test {@link BaseVariableWidthVector#getValueCapacity()}.
80+
*
81+
* @return useless. To avoid DCE by JIT.
82+
*/
83+
@Benchmark
84+
@BenchmarkMode(Mode.AverageTime)
85+
@OutputTimeUnit(TimeUnit.NANOSECONDS)
86+
public int getValueCapacity() {
87+
return vector.getValueCapacity();
88+
}
89+
90+
@Benchmark
91+
@BenchmarkMode(Mode.AverageTime)
92+
@OutputTimeUnit(TimeUnit.MILLISECONDS)
93+
public int setSafeFromArray() {
94+
for (int i = 0; i < 500; ++i) {
95+
vector.setSafe(i * step, bytes);
96+
}
97+
return vector.getBufferSize();
98+
}
99+
100+
@Benchmark
101+
@BenchmarkMode(Mode.AverageTime)
102+
@OutputTimeUnit(TimeUnit.MILLISECONDS)
103+
public int setSafeFromNullableVarcharHolder() {
104+
NullableVarCharHolder nvch = new NullableVarCharHolder();
105+
nvch.buffer = arrowBuff;
106+
nvch.start = 0;
107+
nvch.end = bytes.length;
108+
for (int i = 0; i < 50; ++i) {
109+
nvch.isSet = 0;
110+
for (int j = 0; j < 9; ++j) {
111+
int idx = 10 * i + j;
112+
vector.setSafe(idx, nvch);
113+
}
114+
nvch.isSet = 1;
115+
vector.setSafe(10 * (i + 1), nvch);
116+
}
117+
return vector.getBufferSize();
118+
}
119+
120+
public static void main(String[] args) throws RunnerException {
121+
Options opt =
122+
new OptionsBuilder()
123+
.include(VariableWidthVectorInlineValueBenchmarks.class.getSimpleName())
124+
.forks(1)
125+
.build();
126+
127+
new Runner(opt).run();
128+
}
129+
// checkstyle:on: MissingJavadocMethod
130+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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+
package org.apache.arrow.vector;
18+
19+
import java.util.concurrent.TimeUnit;
20+
import org.apache.arrow.memory.ArrowBuf;
21+
import org.apache.arrow.memory.BufferAllocator;
22+
import org.apache.arrow.memory.RootAllocator;
23+
import org.apache.arrow.vector.holders.NullableViewVarCharHolder;
24+
import org.openjdk.jmh.annotations.Benchmark;
25+
import org.openjdk.jmh.annotations.BenchmarkMode;
26+
import org.openjdk.jmh.annotations.Level;
27+
import org.openjdk.jmh.annotations.Mode;
28+
import org.openjdk.jmh.annotations.OutputTimeUnit;
29+
import org.openjdk.jmh.annotations.Param;
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+
/** Benchmarks for {@link BaseVariableWidthVector}. */
40+
@State(Scope.Benchmark)
41+
public class VariableWidthViewVectorBenchmarks {
42+
// checkstyle:off: MissingJavadocMethod
43+
44+
private static final int VECTOR_CAPACITY = 16 * 1024;
45+
46+
private static final int VECTOR_LENGTH = 1024;
47+
48+
private static final int ALLOCATOR_CAPACITY = 1024 * 1024;
49+
50+
private static byte[] bytes = VariableWidthVectorBenchmarkConstants.LONG_VALUE.getBytes();
51+
private ArrowBuf arrowBuff;
52+
53+
private BufferAllocator allocator;
54+
55+
private ViewVarCharVector vector;
56+
57+
@Param({"1", "2", "10", "40"})
58+
private int step;
59+
60+
/** Setup benchmarks. */
61+
@Setup(Level.Iteration)
62+
public void prepare() {
63+
allocator = new RootAllocator();
64+
vector = new ViewVarCharVector("vector", allocator);
65+
vector.allocateNew(VECTOR_CAPACITY, VECTOR_LENGTH);
66+
arrowBuff = allocator.buffer(VECTOR_LENGTH);
67+
arrowBuff.setBytes(0, bytes, 0, bytes.length);
68+
}
69+
70+
/** Tear down benchmarks. */
71+
@TearDown(Level.Iteration)
72+
public void tearDown() {
73+
arrowBuff.close();
74+
vector.close();
75+
allocator.close();
76+
}
77+
78+
/**
79+
* Test {@link BaseVariableWidthVector#getValueCapacity()}.
80+
*
81+
* @return useless. To avoid DCE by JIT.
82+
*/
83+
@Benchmark
84+
@BenchmarkMode(Mode.AverageTime)
85+
@OutputTimeUnit(TimeUnit.NANOSECONDS)
86+
public int getValueCapacity() {
87+
return vector.getValueCapacity();
88+
}
89+
90+
@Benchmark
91+
@BenchmarkMode(Mode.AverageTime)
92+
@OutputTimeUnit(TimeUnit.MILLISECONDS)
93+
public int setSafeFromArray() {
94+
for (int i = 0; i < 500; ++i) {
95+
vector.setSafe(i * step, bytes);
96+
}
97+
return vector.getBufferSize();
98+
}
99+
100+
@Benchmark
101+
@BenchmarkMode(Mode.AverageTime)
102+
@OutputTimeUnit(TimeUnit.MILLISECONDS)
103+
public int setSafeFromNullableVarcharHolder() {
104+
NullableViewVarCharHolder nvch = new NullableViewVarCharHolder();
105+
nvch.buffer = arrowBuff;
106+
nvch.start = 0;
107+
nvch.end = bytes.length;
108+
for (int i = 0; i < 50; ++i) {
109+
nvch.isSet = 0;
110+
for (int j = 0; j < 9; ++j) {
111+
int idx = 10 * i + j;
112+
vector.setSafe(idx, nvch);
113+
}
114+
nvch.isSet = 1;
115+
vector.setSafe(10 * (i + 1), nvch);
116+
}
117+
return vector.getBufferSize();
118+
}
119+
120+
public static void main(String[] args) throws RunnerException {
121+
Options opt =
122+
new OptionsBuilder()
123+
.include(VariableWidthViewVectorBenchmarks.class.getSimpleName())
124+
.forks(1)
125+
.build();
126+
127+
new Runner(opt).run();
128+
}
129+
// checkstyle:on: MissingJavadocMethod
130+
}

0 commit comments

Comments
 (0)