org.postgresql.benchmark.statement.BindTimestamp Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pgjdbc-benchmark Show documentation
Show all versions of pgjdbc-benchmark Show documentation
PostgreSQL JDBC Driver - benchmarks
/*
* Copyright (c) 2003, PostgreSQL Global Development Group
* See the LICENSE file in the project root for more information.
*/
package org.postgresql.benchmark.statement;
import org.postgresql.benchmark.profilers.FlightRecorderProfiler;
import org.postgresql.util.ConnectionUtil;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.profile.GCProfiler;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Properties;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;
@Fork(value = 1, jvmArgsPrepend = "-Xmx128m")
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@State(Scope.Thread)
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public class BindTimestamp {
private Connection connection;
private PreparedStatement ps;
private Timestamp ts = new Timestamp(System.currentTimeMillis());
private Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
@Setup(Level.Trial)
public void setUp() throws SQLException {
Properties props = ConnectionUtil.getProperties();
connection = DriverManager.getConnection(ConnectionUtil.getURL(), props);
ps = connection.prepareStatement("select ?");
}
@TearDown(Level.Trial)
public void tearDown() throws SQLException {
ps.close();
connection.close();
}
@Benchmark
public Statement timestampLocal() throws SQLException {
ps.setTimestamp(1, ts);
return ps;
}
@Benchmark
public Statement timestampCal() throws SQLException {
ps.setTimestamp(1, ts, cal);
return ps;
}
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(BindTimestamp.class.getSimpleName())
.addProfiler(GCProfiler.class)
.addProfiler(FlightRecorderProfiler.class)
.detectJvmArgs()
.build();
new Runner(opt).run();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy