mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-30 03:40:34 +02:00
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'.
This commit is contained in:
parent
4ff2b9f4b6
commit
07f49ac786
4 changed files with 254 additions and 205 deletions
|
@ -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
|
||||
|
|
52
benchmark-suite/benchmarks/write.bm
Normal file
52
benchmark-suite/benchmarks/write.bm
Normal file
|
@ -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)))
|
Loading…
Add table
Add a link
Reference in a new issue