read.bm 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. ;;; read.bm --- Exercise the reader. -*- Scheme -*-
  2. ;;;
  3. ;;; Copyright (C) 2008, 2010, 2012 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 read)
  20. :use-module (benchmark-suite lib))
  21. (define %files-to-load
  22. ;; Various large Scheme files.
  23. (map %search-load-path
  24. '("ice-9/boot-9.scm" "ice-9/common-list.scm"
  25. "ice-9/format.scm" "ice-9/optargs.scm"
  26. "ice-9/session.scm" "ice-9/getopt-long.scm"
  27. "ice-9/psyntax-pp.scm")))
  28. (define (load-file-with-reader file-name reader buffering)
  29. (with-input-from-file file-name
  30. (lambda ()
  31. (apply setvbuf (current-input-port) buffering)
  32. (let loop ((sexp (reader)))
  33. (if (eof-object? sexp)
  34. #t
  35. (loop (reader)))))))
  36. (define (exercise-read buffering)
  37. (for-each (lambda (file)
  38. (load-file-with-reader file read buffering))
  39. %files-to-load))
  40. (define small "\"hello, world!\"")
  41. (define large (string-append "\"" (make-string 1234 #\A) "\""))
  42. (fluid-set! %default-port-encoding "UTF-8") ; for string ports
  43. (with-benchmark-prefix "read"
  44. (benchmark "'none" 5 ;; this one is very slow
  45. (exercise-read (list 'none)))
  46. (benchmark "'line" 10
  47. (exercise-read (list 'line)))
  48. (benchmark "'block 4096" 10
  49. (exercise-read (list 'block 4096)))
  50. (benchmark "'block 8192" 10
  51. (exercise-read (list 'block 8192)))
  52. (benchmark "'block 16384" 10
  53. (exercise-read (list 'block 16384)))
  54. (benchmark "small strings" 100000
  55. (call-with-input-string small read))
  56. (benchmark "large strings" 100000
  57. (call-with-input-string large read)))