Commit f2e791f4 authored by Yuanle Song's avatar Yuanle Song
Browse files

update c-libpq5 to use env variable

parent d2926843
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -189,3 +189,27 @@ update time cost: 2.72s
select time cost: 0.33s
update time cost: 2.75s
--

** 2019-02-23 pg 9.6, ghc 8.2.2, lts 11.7
seconds: 0.249821547
seconds: 2.703614265
--
seconds: 0.252873544
seconds: 2.662445433
--
seconds: 0.244120763
seconds: 2.655961013
--

** 2019-02-23 pg 9.6, gcc 6.3.0, libpq-dev 10.3-1
0.170
2.598
--
0.172
2.551
--
0.178
2.562
--
0.172
2.589
+3 −1
Original line number Diff line number Diff line
CFLAGS = -std=c99 -O2 -fPIC -pedantic -Wall -Wextra -I/usr/include/postgresql
CFLAGS = -std=c99 -O2 -fPIC -pedantic -Wall -Wextra -Werror -I/usr/include/postgresql
LDFLAGS = -lpq
run: bench
	./bench
bench: bench.c
+3.82 KiB (13.3 KiB)

File changed.

No diff preview for this file type.

+16 −4
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <libpq-fe.h>

@@ -23,7 +24,7 @@ select_test(PGconn *conn)
		res = PQexec(conn, "SELECT id, bar FROM foo");
		if (PQresultStatus(res) != PGRES_TUPLES_OK)
		{
			fprintf(stderr, "SELECT command failed: %s",
			fprintf(stderr, "SELECT command failed: %s\n",
				PQerrorMessage(conn));
			PQclear(res);
			exit_nicely(conn);
@@ -40,7 +41,7 @@ update_test(PGconn *conn)
		res = PQexec(conn, "UPDATE foo SET bar=bar+1 WHERE id=1");
		if (PQresultStatus(res) != PGRES_COMMAND_OK)
		{
			fprintf(stderr, "UPDATE command failed: %s",
			fprintf(stderr, "UPDATE command failed: %s\n",
				PQerrorMessage(conn));
			PQclear(res);
			exit_nicely(conn);
@@ -59,13 +60,24 @@ int
main()
{
	struct timeval start, end;
	const char *conninfo = "host=localhost dbname=t1 user=t1 password=fNfwREMqO69TB9YqE+/OzF5/k+s=";
	const char *password;
	const char *conninfo_part = "host=localhost dbname=t1 user=t1 password=";
	char *conninfo;
	PGconn *conn;

	password = getenv("PG_T1_PASSWORD");
	if (password == NULL) {
		fprintf(stderr, "Please define PG_T1_PASSWORD environment variable\n");
		exit(1);
	}

	conninfo = (char*) malloc(1 + strlen(conninfo_part) + strlen(password));
	strcat(conninfo, conninfo_part);
	strcat(conninfo, password);
	conn = PQconnectdb(conninfo);
	if (PQstatus(conn) != CONNECTION_OK)
	{
		fprintf(stderr, "Connection to database failed: %s",
		fprintf(stderr, "Connection to database failed: %s\n",
			PQerrorMessage(conn));
		exit_nicely(conn);
	}
+9 −4
Original line number Diff line number Diff line
module Main where

import System.Environment (lookupEnv)
import Control.Monad
import Text.Printf
import Data.Time.Clock
@@ -26,7 +27,11 @@ timeit action = do

main :: IO ()
main = do
  conn <- connectPostgreSQL "host=localhost dbname=t1 user=t1 password=fNfwREMqO69TB9YqE+/OzF5/k+s="
  passwordMaybe <- lookupEnv "PG_T1_PASSWORD"
  case passwordMaybe of
    Nothing -> printf "Error: Please define PG_T1_PASSWORD environment variable"
    Just password -> do
      conn <- connectPostgreSQL "host=localhost dbname=t1 user=t1 password=62IWgtWiPCZdt8qu"
      timeit $ selectTest conn
      timeit $ updateTest conn
      close conn
Loading