summaryrefslogtreecommitdiff
path: root/benchmark-suite
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2010-09-14 16:10:52 +0200
committerLudovic Courtès <ludo@gnu.org>2010-09-14 16:11:19 +0200
commit07f49ac786e0f1c007eb336e2fb7a572e8405316 (patch)
treeab04b1efe4ee3062959b659456b3abc53b9d1b6f /benchmark-suite
parent4ff2b9f4b6fab00e0e982ce6d1b2594c19704d6e (diff)
Factorize and optimize `write' for strings and characters.
According to `write.bm', this makes `write' 2.6 times faster for strings. * libguile/print.c (iprin1): Use `write_character' when `SCM_WRITINGP (pstate)' and `SCM_CHARP (exp)' or `scm_is_string (exp)'. (scm_i_charprint): Remove. (display_character, write_character): New functions. (scm_write_char): Use `display_character' instead of `scm_i_charprint'. * libguile/print.h (scm_i_charprint): Remove declaration. * benchmark-suite/benchmarks/write.bm: New file. * benchmark-suite/Makefile.am (SCM_BENCHMARKS): Add `benchmarks/write.bm'.
Diffstat (limited to 'benchmark-suite')
-rw-r--r--benchmark-suite/Makefile.am3
-rw-r--r--benchmark-suite/benchmarks/write.bm52
2 files changed, 54 insertions, 1 deletions
diff --git a/benchmark-suite/Makefile.am b/benchmark-suite/Makefile.am
index b58219a24..9f49f2aad 100644
--- a/benchmark-suite/Makefile.am
+++ b/benchmark-suite/Makefile.am
@@ -11,7 +11,8 @@ SCM_BENCHMARKS = benchmarks/0-reference.bm \
benchmarks/subr.bm \
benchmarks/uniform-vector-read.bm \
benchmarks/vectors.bm \
- benchmarks/vlists.bm
+ benchmarks/vlists.bm \
+ benchmarks/write.bm
EXTRA_DIST = guile-benchmark lib.scm $(SCM_BENCHMARKS) \
ChangeLog-2008
diff --git a/benchmark-suite/benchmarks/write.bm b/benchmark-suite/benchmarks/write.bm
new file mode 100644
index 000000000..e96f2efeb
--- /dev/null
+++ b/benchmark-suite/benchmarks/write.bm
@@ -0,0 +1,52 @@
+;;; write.bm --- Exercise the printer. -*- Scheme -*-
+;;;
+;;; Copyright (C) 2008, 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 read)
+ #:use-module (benchmark-suite lib))
+
+(define %len 50000)
+
+(define %string-with-escapes
+ (list->string (map integer->char (iota %len))))
+
+(define %string-without-escapes
+ (make-string %len #\a))
+
+;; Use Unicode-capable ports.
+(fluid-set! %default-port-encoding "UTF-8")
+
+(define %null
+ (%make-void-port OPEN_WRITE))
+
+
+(with-benchmark-prefix "write"
+
+ (benchmark "string with escapes" 50
+ (write %string-with-escapes %null))
+
+ (benchmark "string without escapes" 50
+ (write %string-without-escapes %null)))
+
+(with-benchmark-prefix "display"
+
+ (benchmark "string with escapes" 1000
+ (display %string-with-escapes %null))
+
+ (benchmark "string without escapes" 1000
+ (display %string-without-escapes %null)))