uniform-vector-read.bm 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. ;;; uniform-vector-read.bm --- Exercise binary I/O primitives. -*- Scheme -*-
  2. ;;;
  3. ;;; Copyright (C) 2008 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 uniform-vector-read)
  20. :use-module (benchmark-suite lib)
  21. :use-module (srfi srfi-4))
  22. (define file-name
  23. (tmpnam))
  24. (define %buffer-size
  25. 7777)
  26. (define buf
  27. (make-u8vector %buffer-size))
  28. (define str
  29. (make-string %buffer-size))
  30. (with-benchmark-prefix "uniform-vector-read!"
  31. (benchmark "uniform-vector-write" 4000
  32. (let ((output (open-output-file file-name)))
  33. (uniform-vector-write buf output)
  34. (close output)))
  35. (benchmark "uniform-vector-read!" 20000
  36. (let ((input (open-input-file file-name)))
  37. (setvbuf input _IONBF)
  38. (uniform-vector-read! buf input)
  39. (close input)))
  40. (benchmark "string port" 5000
  41. (let ((input (open-input-string str)))
  42. (uniform-vector-read! buf input)
  43. (close input))))