diff options
author | Ludovic Courtès <ludo@gnu.org> | 2010-09-15 18:38:57 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2010-09-15 18:38:57 +0200 |
commit | fd5eec2b6e113f6d13028215a738417607432a2d (patch) | |
tree | f87058b9bb6f5d2b4b516763e26c663b7e659f9a /benchmark-suite | |
parent | e9c3018cec8ed236a375c59aed55e66e47671022 (diff) | |
download | guile-fd5eec2b6e113f6d13028215a738417607432a2d.tar.gz |
Optimize `peek-char'.
This makes `peek-char' 40x faster on a port whose encoding is
faster on a UTF-8 port containing multi-byte codepoints.
The `xml->sxml' procedure is 4x faster on a 2.7 MiB XML file.
* libguile/ports.c (get_codepoint): New procedure, moved here from
`scm_getc', with the additional BUF and LEN parameters.
(scm_getc): Use it.
(scm_peek_char): Use it instead of the `scm_getc'/`scm_ungetc'
sequence.
* test-suite/tests/ports.test ("string ports")["peek-char [latin-1]",
"peek-char [utf-8]"]: New tests.
* benchmark-suite/Makefile.am (SCM_BENCHMARKS): Add
`benchmarks/ports.bm'.
* benchmark-suite/benchmarks/ports.bm: New file.
Diffstat (limited to 'benchmark-suite')
-rw-r--r-- | benchmark-suite/Makefile.am | 1 | ||||
-rw-r--r-- | benchmark-suite/benchmarks/ports.bm | 67 |
2 files changed, 68 insertions, 0 deletions
diff --git a/benchmark-suite/Makefile.am b/benchmark-suite/Makefile.am index 9f49f2aad..e2aad9148 100644 --- a/benchmark-suite/Makefile.am +++ b/benchmark-suite/Makefile.am @@ -4,6 +4,7 @@ SCM_BENCHMARKS = benchmarks/0-reference.bm \ benchmarks/continuations.bm \ benchmarks/if.bm \ benchmarks/logand.bm \ + benchmarks/ports.bm \ benchmarks/read.bm \ benchmarks/srfi-1.bm \ benchmarks/srfi-13.bm \ diff --git a/benchmark-suite/benchmarks/ports.bm b/benchmark-suite/benchmarks/ports.bm new file mode 100644 index 000000000..917a7ddbe --- /dev/null +++ b/benchmark-suite/benchmarks/ports.bm @@ -0,0 +1,67 @@ +;;; ports.bm --- Port I/O. -*- mode: scheme; coding: utf-8; -*- +;;; +;;; Copyright (C) 2010 Free Software Foundation, Inc. +;;; +;;; This program is free software; you can redistribute it and/or +;;; modify it under the terms of the GNU Lesser General Public License +;;; as published by the Free Software Foundation; either version 3, or +;;; (at your option) any later version. +;;; +;;; This program is distributed in the hope that it will be useful, +;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU Lesser General Public License for more details. +;;; +;;; You should have received a copy of the GNU Lesser General Public +;;; License along with this software; see the file COPYING.LESSER. If +;;; not, write to the Free Software Foundation, Inc., 51 Franklin +;;; Street, Fifth Floor, Boston, MA 02110-1301 USA + +(define-module (benchmarks ports) + #:use-module (benchmark-suite lib)) + +(define %latin1-port + (with-fluids ((%default-port-encoding #f)) + (open-input-string "hello, world"))) + +(define %utf8/ascii-port + (with-fluids ((%default-port-encoding "UTF-8")) + (open-input-string "hello, world"))) + +(define %utf8/wide-port + (with-fluids ((%default-port-encoding "UTF-8")) + (open-input-string "안녕하세요"))) + + +(with-benchmark-prefix "peek-char" + + (benchmark "latin-1 port" 700000 + (peek-char %latin1-port)) + + (benchmark "utf-8 port, ascii character" 700000 + (peek-char %utf8/ascii-port)) + + (benchmark "utf-8 port, Korean character" 700000 + (peek-char %utf8/wide-port))) + +(with-benchmark-prefix "read-char" + + (benchmark "latin-1 port" 10000000 + (read-char %latin1-port)) + + (benchmark "utf-8 port, ascii character" 10000000 + (read-char %utf8/ascii-port)) + + (benchmark "utf-8 port, Korean character" 10000000 + (read-char %utf8/wide-port))) + +(with-benchmark-prefix "char-ready?" + + (benchmark "latin-1 port" 10000000 + (char-ready? %latin1-port)) + + (benchmark "utf-8 port, ascii character" 10000000 + (char-ready? %utf8/ascii-port)) + + (benchmark "utf-8 port, Korean character" 10000000 + (char-ready? %utf8/wide-port))) |