degenerate let forms
[bpt/guile.git] / benchmark-suite / benchmarks / ports.bm
CommitLineData
fd5eec2b
LC
1;;; ports.bm --- Port I/O. -*- mode: scheme; coding: utf-8; -*-
2;;;
6dce942c 3;;; Copyright (C) 2010, 2011, 2012, 2013 Free Software Foundation, Inc.
fd5eec2b
LC
4;;;
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.
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
13;;; GNU Lesser General Public License for more details.
14;;;
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
19
20(define-module (benchmarks ports)
d9f24bc9 21 #:use-module (ice-9 rdelim)
fd5eec2b
LC
22 #:use-module (benchmark-suite lib))
23
da35d2ea
LC
24(define-syntax sequence
25 (lambda (s)
26 ;; Create a sequence `(begin EXPR ...)' with COUNT occurrences of EXPR.
27 (syntax-case s ()
28 ((_ expr count)
29 (number? (syntax->datum #'count))
30 (cons #'begin
31 (make-list (syntax->datum #'count) #'expr))))))
32
33(define (large-string s)
34 (string-concatenate (make-list (* iteration-factor 10000) s)))
35
fd5eec2b 36(define %latin1-port
6dce942c
MW
37 (let ((p (open-input-string (large-string "hello, world"))))
38 (set-port-encoding! p "ISO-8859-1")
39 p))
fd5eec2b
LC
40
41(define %utf8/ascii-port
6dce942c 42 (open-input-string (large-string "hello, world")))
fd5eec2b
LC
43
44(define %utf8/wide-port
6dce942c 45 (open-input-string (large-string "안녕하세요")))
fd5eec2b
LC
46
47\f
48(with-benchmark-prefix "peek-char"
49
da35d2ea
LC
50 (benchmark "latin-1 port" 700
51 (sequence (peek-char %latin1-port) 1000))
fd5eec2b 52
da35d2ea
LC
53 (benchmark "utf-8 port, ascii character" 700
54 (sequence (peek-char %utf8/ascii-port) 1000))
fd5eec2b 55
da35d2ea
LC
56 (benchmark "utf-8 port, Korean character" 700
57 (sequence (peek-char %utf8/wide-port) 1000)))
fd5eec2b 58
da35d2ea 59(with-benchmark-prefix "char-ready?"
fd5eec2b 60
da35d2ea
LC
61 (benchmark "latin-1 port" 10000
62 (sequence (char-ready? %latin1-port) 1000))
fd5eec2b 63
da35d2ea
LC
64 (benchmark "utf-8 port, ascii character" 10000
65 (sequence (char-ready? %utf8/ascii-port) 1000))
fd5eec2b 66
da35d2ea
LC
67 (benchmark "utf-8 port, Korean character" 10000
68 (sequence (char-ready? %utf8/wide-port) 1000)))
fd5eec2b 69
da35d2ea
LC
70;; Keep the `read-char' benchmarks last as they consume input from the
71;; ports.
72
73(with-benchmark-prefix "read-char"
fd5eec2b 74
da35d2ea
LC
75 (benchmark "latin-1 port" 10000
76 (sequence (read-char %latin1-port) 1000))
fd5eec2b 77
da35d2ea
LC
78 (benchmark "utf-8 port, ascii character" 10000
79 (sequence (read-char %utf8/ascii-port) 1000))
fd5eec2b 80
da35d2ea
LC
81 (benchmark "utf-8 port, Korean character" 10000
82 (sequence (read-char %utf8/wide-port) 1000)))
d9f24bc9
LC
83
84\f
85(with-benchmark-prefix "rdelim"
86
da35d2ea
LC
87 (let ((str (string-concatenate (make-list 1000 "one line\n"))))
88 (benchmark "read-line" 1000
6dce942c 89 (let ((port (open-input-string str)))
da35d2ea 90 (sequence (read-line port) 1000)))))