ports.bm 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. ;;; ports.bm --- Port I/O. -*- mode: scheme; coding: utf-8; -*-
  2. ;;;
  3. ;;; Copyright (C) 2010, 2011 Free Software Foundation, Inc.
  4. ;;;
  5. ;;; This program is free software; you can redistribute it and/or
  6. ;;; modify it under the terms of the GNU Lesser General Public License
  7. ;;; as published by the Free Software Foundation; either version 3, or
  8. ;;; (at your option) any later version.
  9. ;;;
  10. ;;; This program is distributed in the hope that it will be useful,
  11. ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;;; GNU Lesser General Public License for more details.
  14. ;;;
  15. ;;; You should have received a copy of the GNU Lesser General Public
  16. ;;; License along with this software; see the file COPYING.LESSER. If
  17. ;;; not, write to the Free Software Foundation, Inc., 51 Franklin
  18. ;;; Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. (define-module (benchmarks ports)
  20. #:use-module (ice-9 rdelim)
  21. #:use-module (benchmark-suite lib))
  22. (define %latin1-port
  23. (with-fluids ((%default-port-encoding #f))
  24. (open-input-string "hello, world")))
  25. (define %utf8/ascii-port
  26. (with-fluids ((%default-port-encoding "UTF-8"))
  27. (open-input-string "hello, world")))
  28. (define %utf8/wide-port
  29. (with-fluids ((%default-port-encoding "UTF-8"))
  30. (open-input-string "안녕하세요")))
  31. (with-benchmark-prefix "peek-char"
  32. (benchmark "latin-1 port" 700000
  33. (peek-char %latin1-port))
  34. (benchmark "utf-8 port, ascii character" 700000
  35. (peek-char %utf8/ascii-port))
  36. (benchmark "utf-8 port, Korean character" 700000
  37. (peek-char %utf8/wide-port)))
  38. (with-benchmark-prefix "read-char"
  39. (benchmark "latin-1 port" 10000000
  40. (read-char %latin1-port))
  41. (benchmark "utf-8 port, ascii character" 10000000
  42. (read-char %utf8/ascii-port))
  43. (benchmark "utf-8 port, Korean character" 10000000
  44. (read-char %utf8/wide-port)))
  45. (with-benchmark-prefix "char-ready?"
  46. (benchmark "latin-1 port" 10000000
  47. (char-ready? %latin1-port))
  48. (benchmark "utf-8 port, ascii character" 10000000
  49. (char-ready? %utf8/ascii-port))
  50. (benchmark "utf-8 port, Korean character" 10000000
  51. (char-ready? %utf8/wide-port)))
  52. (with-benchmark-prefix "rdelim"
  53. (let-syntax ((sequence (lambda (s)
  54. ;; Create a sequence `(begin EXPR ...)' with
  55. ;; COUNT occurrences of EXPR.
  56. (syntax-case s ()
  57. ((_ expr count)
  58. (number? (syntax->datum #'count))
  59. (cons #'begin
  60. (make-list
  61. (syntax->datum #'count)
  62. #'expr)))))))
  63. (let ((str (string-concatenate
  64. (make-list 1000 "one line\n"))))
  65. (benchmark "read-line" 1000
  66. (let ((port (with-fluids ((%default-port-encoding "UTF-8"))
  67. (open-input-string str))))
  68. (sequence (read-line port) 1000))))))