Commit | Line | Data |
---|---|---|
fd5eec2b LC |
1 | ;;; ports.bm --- Port I/O. -*- mode: scheme; coding: utf-8; -*- |
2 | ;;; | |
d9f24bc9 | 3 | ;;; Copyright (C) 2010, 2011 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 | ||
24 | (define %latin1-port | |
25 | (with-fluids ((%default-port-encoding #f)) | |
26 | (open-input-string "hello, world"))) | |
27 | ||
28 | (define %utf8/ascii-port | |
29 | (with-fluids ((%default-port-encoding "UTF-8")) | |
30 | (open-input-string "hello, world"))) | |
31 | ||
32 | (define %utf8/wide-port | |
33 | (with-fluids ((%default-port-encoding "UTF-8")) | |
34 | (open-input-string "안녕하세요"))) | |
35 | ||
36 | \f | |
37 | (with-benchmark-prefix "peek-char" | |
38 | ||
39 | (benchmark "latin-1 port" 700000 | |
40 | (peek-char %latin1-port)) | |
41 | ||
42 | (benchmark "utf-8 port, ascii character" 700000 | |
43 | (peek-char %utf8/ascii-port)) | |
44 | ||
45 | (benchmark "utf-8 port, Korean character" 700000 | |
46 | (peek-char %utf8/wide-port))) | |
47 | ||
48 | (with-benchmark-prefix "read-char" | |
49 | ||
50 | (benchmark "latin-1 port" 10000000 | |
51 | (read-char %latin1-port)) | |
52 | ||
53 | (benchmark "utf-8 port, ascii character" 10000000 | |
54 | (read-char %utf8/ascii-port)) | |
55 | ||
56 | (benchmark "utf-8 port, Korean character" 10000000 | |
57 | (read-char %utf8/wide-port))) | |
58 | ||
59 | (with-benchmark-prefix "char-ready?" | |
60 | ||
61 | (benchmark "latin-1 port" 10000000 | |
62 | (char-ready? %latin1-port)) | |
63 | ||
64 | (benchmark "utf-8 port, ascii character" 10000000 | |
65 | (char-ready? %utf8/ascii-port)) | |
66 | ||
67 | (benchmark "utf-8 port, Korean character" 10000000 | |
68 | (char-ready? %utf8/wide-port))) | |
d9f24bc9 LC |
69 | |
70 | \f | |
71 | (with-benchmark-prefix "rdelim" | |
72 | ||
73 | (let-syntax ((sequence (lambda (s) | |
74 | ;; Create a sequence `(begin EXPR ...)' with | |
75 | ;; COUNT occurrences of EXPR. | |
76 | (syntax-case s () | |
77 | ((_ expr count) | |
78 | (number? (syntax->datum #'count)) | |
79 | (cons #'begin | |
80 | (make-list | |
81 | (syntax->datum #'count) | |
82 | #'expr))))))) | |
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)))))) |