summaryrefslogtreecommitdiff
path: root/benchmarks/run.scm
diff options
context:
space:
mode:
authorPeter Bex <peter@more-magic.net>2018-06-11 21:39:55 +0200
committerPeter Bex <peter@more-magic.net>2018-06-11 21:56:43 +0200
commit385f6f23fee37617e0148babdb00783775d04a70 (patch)
tree6175f6364667fba196f83bcc328a38f626ee5be0 /benchmarks/run.scm
downloadchicken-postgresql-385f6f23fee37617e0148babdb00783775d04a70.tar.gz
Initial port of PostgreSQL egg to CHICKEN 54.0.0
Diffstat (limited to 'benchmarks/run.scm')
-rw-r--r--benchmarks/run.scm127
1 files changed, 127 insertions, 0 deletions
diff --git a/benchmarks/run.scm b/benchmarks/run.scm
new file mode 100644
index 0000000..2994710
--- /dev/null
+++ b/benchmarks/run.scm
@@ -0,0 +1,127 @@
+(import postgresql (chicken string) (chicken format) srfi-13)
+
+(define conn (connect '((dbname . test))))
+(define raw-conn (connect '((dbname . test)) '() '()))
+
+(print "--- Connecting/disconnecting ---")
+(print "Full connection")
+(time (do ((i 0 (add1 i)))
+ ((= i 1000))
+ (disconnect (connect '((dbname . test))))))
+
+(print "Raw connection")
+(time (do ((i 0 (add1 i)))
+ ((= i 1000))
+ (disconnect (connect '((dbname . test)) '() '()))))
+
+(let ((str (make-string 1000 #\x)))
+ (newline)
+ (print "--- Quotation ---")
+ (print "Escaping many strings")
+ (time (do ((i 0 (add1 i)))
+ ((= i 100000))
+ (escape-string conn str)))
+
+ (print "Quoting many identifiers")
+ (time (do ((i 0 (add1 i)))
+ ((= i 100000))
+ (quote-identifier conn str)))
+
+ (print "Escaping many byteas")
+ (time (do ((i 0 (add1 i)))
+ ((= i 100000))
+ (escape-bytea conn str)))
+
+ (print "Unescaping many byteas")
+ (let ((bytea (escape-bytea conn str)))
+ (time (do ((i 0 (add1 i)))
+ ((= i 100000))
+ (unescape-bytea bytea)))))
+
+(begin (newline)
+ (print "--- Reading data ---")
+ (print "Raw query with no result processing (postgres/libpq benchmark)")
+ (time (query conn "SELECT generate_series(0, 100000)"))
+
+ (newline)
+ (print "Fetching all values, no type conversion (string)")
+ (time (row-for-each (lambda (values) #f)
+ (query raw-conn "SELECT generate_series(0, 1000000)::text")))
+ (print "Fetching all values, with type conversion (string)")
+ (time (row-for-each (lambda (values) #f)
+ (query conn "SELECT generate_series(0, 1000000)::text")))
+
+ (newline)
+ (print "Fetching all values, no type conversion (integer)")
+ (time (row-for-each (lambda (values) #f)
+ (query raw-conn "SELECT generate_series(0, 1000000)")))
+ (print "Fetching all values, with type conversion (integer)")
+ (time (row-for-each (lambda (values) #f)
+ (query conn "SELECT generate_series(0, 1000000)")))
+
+ (newline)
+ (print "COPY TO")
+ (time (copy-query-for-each (lambda (values) #f)
+ raw-conn "COPY (SELECT generate_series(0, 1000000)) TO STDOUT")))
+
+(begin (newline)
+ (print "--- Inserting data ---")
+ (query raw-conn "CREATE TEMPORARY TABLE foo (bar int)")
+ (print "INSERT in a loop, no type conversion")
+ (time (do ((i 0 (add1 i)))
+ ((= i 65535))
+ (query raw-conn "INSERT INTO foo VALUES ($1)" (->string i))))
+ (query raw-conn "TRUNCATE foo")
+
+ (query conn "CREATE TEMPORARY TABLE foo (bar int)")
+ (print "INSERT in a loop, with type conversion")
+ (time (do ((i 0 (add1 i)))
+ ((= i 65535))
+ (query conn "INSERT INTO foo VALUES ($1)" i)))
+ (query conn "TRUNCATE foo")
+
+ (newline)
+
+ (print "Parameterized INSERT statement, no type conversion")
+ (time (do ((i 0 (add1 i))
+ (values '() (cons (->string i) values))
+ (values-string '() (cons (sprintf "($~A)" (add1 i)) values-string)))
+ ((= i 65535)
+ (query* raw-conn (sprintf "INSERT INTO foo VALUES ~A"
+ (string-join values-string ","))
+ values))))
+ (query raw-conn "TRUNCATE foo")
+
+ (print "Parameterized INSERT statement, with type conversion")
+ (time (do ((i 0 (add1 i))
+ (values '() (cons i values))
+ (values-string '() (cons (sprintf "($~A)" (add1 i)) values-string)))
+ ((= i 65535)
+ (query* conn (sprintf "INSERT INTO foo VALUES ~A"
+ (string-join values-string ","))
+ values))))
+ (query conn "TRUNCATE foo")
+
+ (newline)
+
+ (print "Unparameterized INSERT statement")
+ (time (do ((i 0 (add1 i))
+ (values-string '() (cons (sprintf "(~A)" i) values-string)))
+ ((= i 65535)
+ (query raw-conn (sprintf "INSERT INTO foo VALUES ~A"
+ (string-join values-string ","))))))
+ (query raw-conn "TRUNCATE foo")
+
+ (newline)
+ (print "COPY FROM")
+ (time (call-with-output-copy-query
+ (lambda (p)
+ (do ((i 0 (add1 i)))
+ ((= i 65535))
+ (display i p)
+ (newline p)))
+ raw-conn "COPY foo (bar) FROM STDIN"))
+ (query raw-conn "TRUNCATE foo"))
+
+(disconnect raw-conn)
+(disconnect conn)