Optimize `1+' and `1-' on fixnums.
[bpt/guile.git] / benchmark-suite / benchmarks / ports.bm
1 ;;; ports.bm --- Port I/O. -*- mode: scheme; coding: utf-8; -*-
2 ;;;
3 ;;; Copyright (C) 2010 Free Software Foundation, Inc.
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)
21 #:use-module (benchmark-suite lib))
22
23 (define %latin1-port
24 (with-fluids ((%default-port-encoding #f))
25 (open-input-string "hello, world")))
26
27 (define %utf8/ascii-port
28 (with-fluids ((%default-port-encoding "UTF-8"))
29 (open-input-string "hello, world")))
30
31 (define %utf8/wide-port
32 (with-fluids ((%default-port-encoding "UTF-8"))
33 (open-input-string "안녕하세요")))
34
35 \f
36 (with-benchmark-prefix "peek-char"
37
38 (benchmark "latin-1 port" 700000
39 (peek-char %latin1-port))
40
41 (benchmark "utf-8 port, ascii character" 700000
42 (peek-char %utf8/ascii-port))
43
44 (benchmark "utf-8 port, Korean character" 700000
45 (peek-char %utf8/wide-port)))
46
47 (with-benchmark-prefix "read-char"
48
49 (benchmark "latin-1 port" 10000000
50 (read-char %latin1-port))
51
52 (benchmark "utf-8 port, ascii character" 10000000
53 (read-char %utf8/ascii-port))
54
55 (benchmark "utf-8 port, Korean character" 10000000
56 (read-char %utf8/wide-port)))
57
58 (with-benchmark-prefix "char-ready?"
59
60 (benchmark "latin-1 port" 10000000
61 (char-ready? %latin1-port))
62
63 (benchmark "utf-8 port, ascii character" 10000000
64 (char-ready? %utf8/ascii-port))
65
66 (benchmark "utf-8 port, Korean character" 10000000
67 (char-ready? %utf8/wide-port)))