Permalink
Browse files

test: add performance test for "reused vs non-reused at client side" …

…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 2d70385f06d8f58a59a618f1967ac0634a6b925c
Showing with 18 additions and 2 deletions.
  1. +18 −2 ubenchmark/src/main/java/org/postgresql/benchmark/statement/ProcessResultSet.java
@@ -79,8 +79,14 @@
@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;
@@ -89,6 +95,10 @@
@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());
@@ -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)
@@ -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()) {
@@ -150,7 +164,9 @@ public Statement bindExecuteFetch(Blackhole b) throws SQLException {
}
}
rs.close();
ps.close();
if (!reuseStatement) {
ps.close();
}
return ps;
}

0 comments on commit 2d70385

Please sign in to comment.