Skip to content

Commit

Permalink
test: add performance test for "reused vs non-reused at client side" …
Browse files Browse the repository at this point in the history
…prepared statements

TL;DR: the difference is not significant

Benchmark                                              (columnIndexType)  (getter)  (ncols)  (nrows)  (reuseStatement)  (type)  (unique)  Mode  Cnt    Score      Error   Units
ProcessResultSet.bindExecuteFetch                                  INDEX      BEST        1        1              true     INT     false  avgt   10   38,899 ±    0,508   us/op
ProcessResultSet.bindExecuteFetch:·gc.alloc.rate.norm              INDEX      BEST        1        1              true     INT     false  avgt   10  464,069 ±    0,228    B/op
ProcessResultSet.bindExecuteFetch                                  INDEX      BEST        1        1             false     INT     false  avgt   10   39,724 ±    0,454   us/op
ProcessResultSet.bindExecuteFetch:·gc.alloc.rate.norm              INDEX      BEST        1        1             false     INT     false  avgt   10  752,070 ±    0,232    B/op
  • Loading branch information
vlsi committed Sep 6, 2016
1 parent 9bc194a commit 2d70385
Showing 1 changed file with 18 additions and 2 deletions.
Expand Up @@ -79,8 +79,14 @@ public enum GetterType {
@Param({"NAME"})
public ColumnIndexType columnIndexType;

// Reuse == false is in line with what most applications do. They never reuse PreparedStatement objects
@Param({"false"})
public boolean reuseStatement;

private Connection connection;

private PreparedStatement ps;

private String sql;

private int cntr;
Expand All @@ -89,6 +95,10 @@ public enum GetterType {

@Setup(Level.Trial)
public void setUp() throws SQLException {
if (reuseStatement && unique) {
System.out.println("It does not make sense to test reuseStatement && unique combination. Terminating to save time");
System.exit(-1);
}
if (type == FieldType.TIMESTAMP) {
System.out.println(
"TimeZone.getDefault().getDisplayName() = " + TimeZone.getDefault().getDisplayName());
Expand Down Expand Up @@ -124,6 +134,9 @@ public void setUp() throws SQLException {
}
sb.append(" from generate_series(1, ?) as t(x)");
sql = sb.toString();
if (reuseStatement) {
this.ps = connection.prepareStatement(sql);
}
}

@TearDown(Level.Trial)
Expand All @@ -137,7 +150,8 @@ public Statement bindExecuteFetch(Blackhole b) throws SQLException {
if (unique) {
sql += " -- " + cntr++;
}
PreparedStatement ps = connection.prepareStatement(sql);

PreparedStatement ps = reuseStatement ? this.ps : connection.prepareStatement(sql);
ps.setInt(1, nrows);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
Expand All @@ -150,7 +164,9 @@ public Statement bindExecuteFetch(Blackhole b) throws SQLException {
}
}
rs.close();
ps.close();
if (!reuseStatement) {
ps.close();
}
return ps;
}

Expand Down

0 comments on commit 2d70385

Please sign in to comment.