summaryrefslogtreecommitdiff
path: root/benchmarks/run.scm
blob: 2994710c4200d42b4281faa4617cd564e29fd781 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
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)