defconst, defvar: proclaim special at compile-time
[bpt/guile.git] / benchmark-suite / benchmarks / read.bm
CommitLineData
6bb1dc98
LC
1;;; read.bm --- Exercise the reader. -*- Scheme -*-
2;;;
ff4d3672 3;;; Copyright (C) 2008, 2010, 2012 Free Software Foundation, Inc.
6bb1dc98 4;;;
53befeb7
NJ
5;;; This program is free software; you can redistribute it and/or
6;;; modify it under the terms of the GNU Lesser General Public License
7;;; as published by the Free Software Foundation; either version 3, or
8;;; (at your option) any later version.
6bb1dc98
LC
9;;;
10;;; This program is distributed in the hope that it will be useful,
11;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
53befeb7 13;;; GNU Lesser General Public License for more details.
6bb1dc98 14;;;
53befeb7
NJ
15;;; You should have received a copy of the GNU Lesser General Public
16;;; License along with this software; see the file COPYING.LESSER. If
17;;; not, write to the Free Software Foundation, Inc., 51 Franklin
18;;; Street, Fifth Floor, Boston, MA 02110-1301 USA
6bb1dc98
LC
19
20(define-module (benchmarks read)
21 :use-module (benchmark-suite lib))
22
23\f
24(define %files-to-load
25 ;; Various large Scheme files.
26 (map %search-load-path
27 '("ice-9/boot-9.scm" "ice-9/common-list.scm"
28 "ice-9/format.scm" "ice-9/optargs.scm"
29 "ice-9/session.scm" "ice-9/getopt-long.scm"
689af211 30 "ice-9/psyntax-pp.scm")))
6bb1dc98
LC
31
32(define (load-file-with-reader file-name reader buffering)
33 (with-input-from-file file-name
34 (lambda ()
35 (apply setvbuf (current-input-port) buffering)
36 (let loop ((sexp (reader)))
37 (if (eof-object? sexp)
38 #t
39 (loop (reader)))))))
40
41(define (exercise-read buffering)
42 (for-each (lambda (file)
43 (load-file-with-reader file read buffering))
44 %files-to-load))
45
ff4d3672
LC
46(define small "\"hello, world!\"")
47(define large (string-append "\"" (make-string 1234 #\A) "\""))
48
49(fluid-set! %default-port-encoding "UTF-8") ; for string ports
50
6bb1dc98
LC
51\f
52(with-benchmark-prefix "read"
53
54 (benchmark "_IONBF" 5 ;; this one is very slow
55 (exercise-read (list _IONBF)))
56
59047043 57 (benchmark "_IOLBF" 10
6bb1dc98
LC
58 (exercise-read (list _IOLBF)))
59
59047043 60 (benchmark "_IOFBF 4096" 10
6bb1dc98
LC
61 (exercise-read (list _IOFBF 4096)))
62
59047043 63 (benchmark "_IOFBF 8192" 10
6bb1dc98
LC
64 (exercise-read (list _IOFBF 8192)))
65
59047043 66 (benchmark "_IOFBF 16384" 10
ff4d3672
LC
67 (exercise-read (list _IOFBF 16384)))
68
69 (benchmark "small strings" 100000
70 (call-with-input-string small read))
71
72 (benchmark "large strings" 100000
73 (call-with-input-string large read)))