r9219: sql/relations.lisp: fix to add subclassing support, minor optimizations [Edi...
[clsql.git] / tests / benchmarks.lisp
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; ======================================================================
3 ;;;; File:    benchmarks.lisp
4 ;;;; Authors: Kevin Rosenberg
5 ;;;; Created: 03/05/2004
6 ;;;; Updated: $Id: test-init.lisp 9212 2004-05-03 18:44:03Z kevin $
7 ;;;;
8 ;;;; Benchmark suite
9 ;;;;
10 ;;;; This file is part of CLSQL.
11 ;;;;
12 ;;;; CLSQL users are granted the rights to distribute and use this software
13 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
14 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
15 ;;;; ======================================================================
16
17 (in-package #:clsql-tests)
18
19 (defun run-benchmarks-append-report-file (report-file)
20   (run-function-append-report-file 'run-benchmarks report-file))
21
22 (clsql:def-view-class bench ()
23   ((a :initarg :a
24       :type integer)
25    (b :initarg :b
26       :type (string 100))
27    (c :initarg :c
28       :type float)))
29    
30 (defun run-benchmarks (&key (report-stream *standard-output*) (sexp-report-stream nil) (count 10000))
31   (let ((specs (read-specs))
32         (*report-stream* report-stream)
33         (*sexp-report-stream* sexp-report-stream))
34     (unless specs
35       (warn "Not running benchmarks because test configuration file is missing")
36       (return-from run-benchmarks :skipped))
37     (load-necessary-systems specs)
38     (dolist (db-type +all-db-types+)
39       (dolist (spec (db-type-spec db-type specs))
40         (do-benchmarks-for-backend db-type spec count))))
41   (values))
42
43 (defun do-benchmarks-for-backend (db-type spec count)
44   (test-connect-to-database db-type spec)
45   (write-report-banner "Benchmarks" db-type *report-stream*)
46
47   (create-view-from-class 'bench)
48   (benchmark-init)
49   (benchmark-selects count)
50   (drop-view-from-class 'bench))
51
52 (defun benchmark-init ()
53   (dotimes (i 10)
54     (execute-command "INSERT INTO BENCH (A,B,C) VALUES (123,'A Medium size string',3.14159)")))
55
56 (defun benchmark-selects (n)
57   (let ((*trace-output* *report-stream*))
58     (format *report-stream* "~&~%*** QUERY ***~%")
59     (time
60      (dotimes (i n)
61        (query "SELECT * FROM BENCH")))
62     (format *report-stream* "~&~%*** QUERY WITH RESULT-TYPES NIL ***~%")
63     (time
64      (dotimes (i n)
65        (query "SELECT * FROM BENCH" :result-types nil)))
66     (format *report-stream* "~&~%*** QUERY WITH FIELD-NAMES NIL ***~%")
67     (time
68      (dotimes (i n)
69        (query "SELECT * FROM BENCH" :field-names nil)))
70     ))
71
72
73
74