Skip to content

Commit fd2f5c5

Browse files
author
diego Dupin
committed
[misc] adding INSERT micro-benchmark test
1 parent d1f85ca commit fd2f5c5

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/benchmark/java/org/mariadb/jdbc/Common.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,20 @@ public static class SetupData {
9696
"jdbc:mariadb://%s:%s/%s?user=%s&password=%s",
9797
host, port, database, username, password))) {
9898
Statement stmt = conn.createStatement();
99+
try {
100+
stmt.executeQuery("INSTALL SONAME 'ha_blackhole'");
101+
} catch (SQLException e) {
102+
// eat
103+
}
104+
stmt.executeUpdate("DROP TABLE IF EXISTS testBlackHole");
99105
stmt.executeUpdate("DROP TABLE IF EXISTS test100");
106+
107+
try {
108+
stmt.executeUpdate("CREATE TABLE testBlackHole (id INT, t VARCHAR(256)) ENGINE = BLACKHOLE");
109+
} catch (SQLException e) {
110+
stmt.executeUpdate("CREATE TABLE testBlackHole (id INT, t VARCHAR(256))");
111+
}
112+
100113
StringBuilder sb = new StringBuilder("CREATE TABLE test100 (i1 int");
101114
StringBuilder sb2 = new StringBuilder("INSERT INTO test100 value (1");
102115
for (int i = 2; i <= 100; i++) {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// SPDX-License-Identifier: LGPL-2.1-or-later
2+
// Copyright (c) 2012-2014 Monty Program Ab
3+
// Copyright (c) 2015-2021 MariaDB Corporation Ab
4+
5+
package org.mariadb.jdbc;
6+
7+
import org.openjdk.jmh.annotations.Benchmark;
8+
9+
import java.sql.Connection;
10+
import java.sql.PreparedStatement;
11+
12+
public class Insert extends Common {
13+
14+
@Benchmark
15+
public int text(MyState state) throws Throwable {
16+
return run(state.connectionText);
17+
}
18+
19+
@Benchmark
20+
public int binary(MyState state) throws Throwable {
21+
return run(state.connectionBinary);
22+
}
23+
24+
private int run(Connection con) throws Throwable {
25+
26+
try (PreparedStatement prep = con.prepareStatement("INSERT INTO testBlackHole values (?,?)")) {
27+
prep.setInt(1, 1);
28+
prep.setString(2, "azertyuiop");
29+
return prep.executeUpdate();
30+
}
31+
}
32+
33+
}

0 commit comments

Comments
 (0)