1 ;;; ports.bm --- Port I/O. -*- mode: scheme; coding: utf-8; -*-
3 ;;; Copyright (C) 2010, 2011 Free Software Foundation, Inc.
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.
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.
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
20 (define-module (benchmarks ports)
21 #:use-module (ice-9 rdelim)
22 #:use-module (benchmark-suite lib))
25 (with-fluids ((%default-port-encoding #f))
26 (open-input-string "hello, world")))
28 (define %utf8/ascii-port
29 (with-fluids ((%default-port-encoding "UTF-8"))
30 (open-input-string "hello, world")))
32 (define %utf8/wide-port
33 (with-fluids ((%default-port-encoding "UTF-8"))
34 (open-input-string "안녕하세요")))
37 (with-benchmark-prefix "peek-char"
39 (benchmark "latin-1 port" 700000
40 (peek-char %latin1-port))
42 (benchmark "utf-8 port, ascii character" 700000
43 (peek-char %utf8/ascii-port))
45 (benchmark "utf-8 port, Korean character" 700000
46 (peek-char %utf8/wide-port)))
48 (with-benchmark-prefix "read-char"
50 (benchmark "latin-1 port" 10000000
51 (read-char %latin1-port))
53 (benchmark "utf-8 port, ascii character" 10000000
54 (read-char %utf8/ascii-port))
56 (benchmark "utf-8 port, Korean character" 10000000
57 (read-char %utf8/wide-port)))
59 (with-benchmark-prefix "char-ready?"
61 (benchmark "latin-1 port" 10000000
62 (char-ready? %latin1-port))
64 (benchmark "utf-8 port, ascii character" 10000000
65 (char-ready? %utf8/ascii-port))
67 (benchmark "utf-8 port, Korean character" 10000000
68 (char-ready? %utf8/wide-port)))
71 (with-benchmark-prefix "rdelim"
73 (let-syntax ((sequence (lambda (s)
74 ;; Create a sequence `(begin EXPR ...)' with
75 ;; COUNT occurrences of EXPR.
78 (number? (syntax->datum #'count))
81 (syntax->datum #'count)
83 (let ((str (string-concatenate
84 (make-list 1000 "one line\n"))))
85 (benchmark "read-line" 1000
86 (let ((port (with-fluids ((%default-port-encoding "UTF-8"))
87 (open-input-string str))))
88 (sequence (read-line port) 1000))))))