Skip to content

Commit

Permalink
[misc] benchmark improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Nov 13, 2023
1 parent 93cbcf0 commit f302694
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/benchmark/java/org/mariadb/jdbc/Common.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static class MyState {


@Param({
//"mysql",
"mysql",
"mariadb"})
String driver;
@Setup(Level.Trial)
Expand Down
17 changes: 8 additions & 9 deletions src/benchmark/java/org/mariadb/jdbc/Select_1000_Rows.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,29 @@
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.infra.Blackhole;

public class Select_1000_Rows extends Common {
private static final String sql =
"select seq, 'abcdefghijabcdefghijabcdefghijaa' from seq_1_to_1000";

@Benchmark
public int text(MyState state) throws Throwable {
return run(state.connectionText);
public void text(MyState state, Blackhole blackhole) throws Throwable {
run(state.connectionText, blackhole);
}

@Benchmark
public int binary(MyState state) throws Throwable {
return run(state.connectionBinary);
public void binary(MyState state, Blackhole blackhole) throws Throwable {
run(state.connectionBinary, blackhole);
}

private int run(Connection con) throws Throwable {
private void run(Connection con, Blackhole blackhole) throws Throwable {
try (PreparedStatement st = con.prepareStatement(sql)) {
ResultSet rs = st.executeQuery();
int i = 0;
while (rs.next()) {
i = rs.getInt(1);
rs.getString(2);
blackhole.consume(rs.getInt(1));
blackhole.consume(rs.getString(2));
}
return i;
}
}
}
30 changes: 15 additions & 15 deletions src/benchmark/java/org/mariadb/jdbc/Select_100_cols.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,40 @@
import java.sql.*;
import java.sql.Connection;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.infra.Blackhole;

public class Select_100_cols extends Common {

@Benchmark
public int[] text(MyState state) throws Throwable {
return run(state.connectionText);
public void text(MyState state, Blackhole blackhole) throws Throwable {
run(state.connectionText, blackhole);
}

@Benchmark
public int[] binary(MyState state) throws Throwable {
return run(state.connectionBinary);
public void binary(MyState state, Blackhole blackhole) throws Throwable {
run(state.connectionBinary, blackhole);
}

@Benchmark
public int[] binaryNoCache(MyState state) throws Throwable {
return run(state.connectionBinaryNoCache);
public void binaryNoCache(MyState state, Blackhole blackhole) throws Throwable {
run(state.connectionBinaryNoCache, blackhole);
}

@Benchmark
public int[] binaryNoPipeline(MyState state) throws Throwable {
return run(state.connectionBinaryNoPipeline);
public void binaryNoPipeline(MyState state, Blackhole blackhole) throws Throwable {
run(state.connectionBinaryNoPipeline, blackhole);
}


private int[] run(Connection con) throws Throwable {
private void run(Connection con, Blackhole blackhole) throws Throwable {

try (PreparedStatement prep = con.prepareStatement("select * FROM test100")) {
ResultSet rs = prep.executeQuery();
rs.next();
int[] objs = new int[100];
for (int i = 0; i < 100; i++) {
objs[i] = rs.getInt(i + 1);
try (ResultSet rs = prep.executeQuery()) {
rs.next();
for (int i = 0; i < 100; i++) {
blackhole.consume(rs.getInt(i + 1));
}
}
return objs;
}
}

Expand Down

0 comments on commit f302694

Please sign in to comment.