Skip to content

Commit 27f0f15

Browse files
committed
Add a simple benchmark for statement parser
Also fixes the pom to run the annotation processor so that mvn -Pbenchmark actually is able to run benchmarks.
1 parent 4cf5261 commit 27f0f15

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

google-cloud-spanner/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,19 @@
517517
</execution>
518518
</executions>
519519
</plugin>
520+
<plugin>
521+
<groupId>org.apache.maven.plugins</groupId>
522+
<artifactId>maven-compiler-plugin</artifactId>
523+
<configuration>
524+
<annotationProcessorPaths>
525+
<path>
526+
<groupId>org.openjdk.jmh</groupId>
527+
<artifactId>jmh-generator-annprocess</artifactId>
528+
<version>1.37</version>
529+
</path>
530+
</annotationProcessorPaths>
531+
</configuration>
532+
</plugin>
520533
</plugins>
521534
</build>
522535
</profile>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.cloud.spanner.connection;
18+
19+
import com.google.cloud.spanner.Dialect;
20+
import org.openjdk.jmh.annotations.Benchmark;
21+
import org.openjdk.jmh.annotations.Fork;
22+
import org.openjdk.jmh.annotations.Measurement;
23+
import org.openjdk.jmh.annotations.Warmup;
24+
25+
@Fork(value = 1, warmups = 0)
26+
@Warmup(iterations = 1, time = 5)
27+
@Measurement(iterations = 5, time = 5)
28+
public class StatementParserBenchmark {
29+
private static final Dialect dialect = Dialect.POSTGRESQL;
30+
private static final AbstractStatementParser parser =
31+
AbstractStatementParser.getInstance(dialect);
32+
33+
private static String longQueryText = generateLongQuery(100 * 1024); // 100kb
34+
35+
/** Generates a long SQL-looking string. */
36+
private static String generateLongQuery(int length) {
37+
StringBuilder sb = new StringBuilder(length + 50);
38+
sb.append("SELECT * FROM foo WHERE 1");
39+
while (sb.length() < length) {
40+
sb.append(" OR abcdefghijklmnopqrstuvwxyz");
41+
}
42+
return sb.toString();
43+
}
44+
45+
@Benchmark
46+
public boolean isQueryTest() {
47+
return parser.isQuery("CREATE TABLE FOO (ID INT64, NAME STRING(100)) PRIMARY KEY (ID)");
48+
}
49+
50+
@Benchmark
51+
public boolean longQueryTest() {
52+
return parser.isQuery(longQueryText);
53+
}
54+
}

0 commit comments

Comments
 (0)