diff options
author | Ludovic Courtès <ludo@gnu.org> | 2012-05-07 00:32:01 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2012-05-07 00:32:01 +0200 |
commit | ff4d3672757fec3c8509e26bc60abf95f9e8f51a (patch) | |
tree | 48c928690b6d8e7b68cf0316c998b96de24c4d67 /benchmark-suite | |
parent | 5bbd632fc36b14f59d51e4ba2d8e189fd3cc0f76 (diff) |
Optimize `scm_read_string'.
According to the new benchmarks, this leads a 5% speed improvement when
reading small strings, and a 27% improvement when reading large strings.
* libguile/read.c (READER_STRING_BUFFER_SIZE): Change to 128; update
comment to mention codepoints.
(scm_read_string): Make `str' a list of strings, instead of a string.
Store characters read in buffer `c_str'. Cons to STR when C_STR is
full, and concatenate/reverse at the end.
* benchmark-suite/benchmarks/read.bm (small, large): New variables.
Set %DEFAULT-PORT-ENCODING to "UTF-8".
("read")["small strings", "large strings"]: New benchmarks.
Diffstat (limited to 'benchmark-suite')
-rw-r--r-- | benchmark-suite/benchmarks/read.bm | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/benchmark-suite/benchmarks/read.bm b/benchmark-suite/benchmarks/read.bm index e5cf7de93..f0b25f541 100644 --- a/benchmark-suite/benchmarks/read.bm +++ b/benchmark-suite/benchmarks/read.bm @@ -1,6 +1,6 @@ ;;; read.bm --- Exercise the reader. -*- Scheme -*- ;;; -;;; Copyright (C) 2008, 2010 Free Software Foundation, Inc. +;;; Copyright (C) 2008, 2010, 2012 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 @@ -43,6 +43,11 @@ (load-file-with-reader file read buffering)) %files-to-load)) +(define small "\"hello, world!\"") +(define large (string-append "\"" (make-string 1234 #\A) "\"")) + +(fluid-set! %default-port-encoding "UTF-8") ; for string ports + (with-benchmark-prefix "read" @@ -59,4 +64,10 @@ (exercise-read (list _IOFBF 8192))) (benchmark "_IOFBF 16384" 10 - (exercise-read (list _IOFBF 16384)))) + (exercise-read (list _IOFBF 16384))) + + (benchmark "small strings" 100000 + (call-with-input-string small read)) + + (benchmark "large strings" 100000 + (call-with-input-string large read))) |