import java.sql.*;

public class Values1 {
    // usage: Values1 url warmup-sec steady-sec
    public static void main(String[] args) throws SQLException {
        final String url = args[0];
        final long warmup = Integer.parseInt(args[1]) * 1000L;
        final long steady = Integer.parseInt(args[2]) * 1000L;

        Connection conn = DriverManager.getConnection(url);
        conn.clearWarnings();

        PreparedStatement ps = conn.prepareStatement("VALUES 1");

        System.out.print("warmup...");
        runTest(ps, warmup);
        System.out.println("done");

        double tps = runTest(ps, steady);
        System.out.println("TPS: " + tps);
    }

    private static double runTest(PreparedStatement ps, long duration)
            throws SQLException {
        final long start = System.currentTimeMillis();
        final long end = start + duration;
        long count = 0;
        long now;
        while ((now = System.currentTimeMillis()) < end) {
            ResultSet rs = ps.executeQuery();
            rs.next();
            int x = rs.getInt(1);
            rs.close();
            count++;
        }
        return (double) count * 1000 / (now - start);
    }
}
