Commit | Line | Data |
---|---|---|
fd5eec2b LC |
1 | ;;; ports.bm --- Port I/O. -*- mode: scheme; coding: utf-8; -*- |
2 | ;;; | |
da35d2ea | 3 | ;;; Copyright (C) 2010, 2011, 2012 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 LC |
36 | (define %latin1-port |
37 | (with-fluids ((%default-port-encoding #f)) | |
da35d2ea | 38 | (open-input-string (large-string "hello, world")))) |
fd5eec2b LC |
39 | |
40 | (define %utf8/ascii-port | |
41 | (with-fluids ((%default-port-encoding "UTF-8")) | |
da35d2ea | 42 | (open-input-string (large-string "hello, world")))) |
fd5eec2b LC |
43 | |
44 | (define %utf8/wide-port | |
45 | (with-fluids ((%default-port-encoding "UTF-8")) | |
da35d2ea | 46 | (open-input-string (large-string "안녕하세요")))) |
fd5eec2b LC |
47 | |
48 | \f | |
49 | (with-benchmark-prefix "peek-char" | |
50 | ||
da35d2ea LC |
51 | (benchmark "latin-1 port" 700 |
52 | (sequence (peek-char %latin1-port) 1000)) | |
fd5eec2b | 53 | |
da35d2ea LC |
54 | (benchmark "utf-8 port, ascii character" 700 |
55 | (sequence (peek-char %utf8/ascii-port) 1000)) | |
fd5eec2b | 56 | |
da35d2ea LC |
57 | (benchmark "utf-8 port, Korean character" 700 |
58 | (sequence (peek-char %utf8/wide-port) 1000))) | |
fd5eec2b | 59 | |
da35d2ea | 60 | (with-benchmark-prefix "char-ready?" |
fd5eec2b | 61 | |
da35d2ea LC |
62 | (benchmark "latin-1 port" 10000 |
63 | (sequence (char-ready? %latin1-port) 1000)) | |
fd5eec2b | 64 | |
da35d2ea LC |
65 | (benchmark "utf-8 port, ascii character" 10000 |
66 | (sequence (char-ready? %utf8/ascii-port) 1000)) | |
fd5eec2b | 67 | |
da35d2ea LC |
68 | (benchmark "utf-8 port, Korean character" 10000 |
69 | (sequence (char-ready? %utf8/wide-port) 1000))) | |
fd5eec2b | 70 | |
da35d2ea LC |
71 | ;; Keep the `read-char' benchmarks last as they consume input from the |
72 | ;; ports. | |
73 | ||
74 | (with-benchmark-prefix "read-char" | |
fd5eec2b | 75 | |
da35d2ea LC |
76 | (benchmark "latin-1 port" 10000 |
77 | (sequence (read-char %latin1-port) 1000)) | |
fd5eec2b | 78 | |
da35d2ea LC |
79 | (benchmark "utf-8 port, ascii character" 10000 |
80 | (sequence (read-char %utf8/ascii-port) 1000)) | |
fd5eec2b | 81 | |
da35d2ea LC |
82 | (benchmark "utf-8 port, Korean character" 10000 |
83 | (sequence (read-char %utf8/wide-port) 1000))) | |
d9f24bc9 LC |
84 | |
85 | \f | |
86 | (with-benchmark-prefix "rdelim" | |
87 | ||
da35d2ea LC |
88 | (let ((str (string-concatenate (make-list 1000 "one line\n")))) |
89 | (benchmark "read-line" 1000 | |
90 | (let ((port (with-fluids ((%default-port-encoding "UTF-8")) | |
91 | (open-input-string str)))) | |
92 | (sequence (read-line port) 1000))))) |