1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 03:40:34 +02:00
guile/benchmark-suite/benchmarks/ports.bm
Mark H Weaver 856d318a9f Merge branch 'stable-2.0'
Conflicts:
	benchmark-suite/benchmarks/ports.bm
	libguile/async.h
	libguile/bytevectors.c
	libguile/foreign.c
	libguile/gsubr.c
	libguile/srfi-1.c
	libguile/vm-engine.h
	libguile/vm-i-scheme.c
	module/Makefile.am
	module/language/tree-il/analyze.scm
	module/language/tree-il/peval.scm
	module/scripts/compile.scm
	module/scripts/disassemble.scm
	test-suite/tests/asm-to-bytecode.test
	test-suite/tests/peval.test
	test-suite/tests/rdelim.test
2014-09-30 03:50:47 -04:00

95 lines
3.1 KiB
Scheme
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

;;; ports.bm --- Port I/O. -*- mode: scheme; coding: utf-8; -*-
;;;
;;; Copyright (C) 2010-2014 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 (ice-9 rdelim)
#:use-module (benchmark-suite lib))
(define-syntax sequence
(lambda (s)
;; Create a sequence `(begin EXPR ...)' with COUNT occurrences of EXPR.
(syntax-case s ()
((_ expr count)
(number? (syntax->datum #'count))
(cons #'begin
(make-list (syntax->datum #'count) #'expr))))))
(define (large-string s)
(string-concatenate (make-list (* iteration-factor 10000) s)))
(define %latin1-port
(let ((p (open-input-string (large-string "hello, world"))))
(set-port-encoding! p "ISO-8859-1")
p))
(define %utf8/ascii-port
(open-input-string (large-string "hello, world")))
(define %utf8/wide-port
(open-input-string (large-string "안녕하세요")))
(with-benchmark-prefix "peek-char"
(benchmark "latin-1 port" 700
(sequence (peek-char %latin1-port) 1000))
(benchmark "utf-8 port, ascii character" 700
(sequence (peek-char %utf8/ascii-port) 1000))
(benchmark "utf-8 port, Korean character" 700
(sequence (peek-char %utf8/wide-port) 1000)))
(with-benchmark-prefix "char-ready?"
(benchmark "latin-1 port" 10000
(sequence (char-ready? %latin1-port) 1000))
(benchmark "utf-8 port, ascii character" 10000
(sequence (char-ready? %utf8/ascii-port) 1000))
(benchmark "utf-8 port, Korean character" 10000
(sequence (char-ready? %utf8/wide-port) 1000)))
;; Keep the `read-char' benchmarks last as they consume input from the
;; ports.
(with-benchmark-prefix "read-char"
(benchmark "latin-1 port" 10000
(sequence (read-char %latin1-port) 1000))
(benchmark "utf-8 port, ascii character" 10000
(sequence (read-char %utf8/ascii-port) 1000))
(benchmark "utf-8 port, Korean character" 10000
(sequence (read-char %utf8/wide-port) 1000)))
(with-benchmark-prefix "rdelim"
(let ((str (string-concatenate (make-list 1000 "one line\n"))))
(benchmark "read-line" 1000
(let ((port (open-input-string str)))
(sequence (read-line port) 1000))))
(let ((str (large-string "Hello, world.\n")))
(benchmark "read-string" 200
(let ((port (open-input-string str)))
(read-string port)))))