bytevectors.bm 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. ;;; -*- mode: scheme; coding: iso-8859-1; -*-
  2. ;;; R6RS Byte Vectors.
  3. ;;;
  4. ;;; Copyright 2009, 2010 Free Software Foundation, Inc.
  5. ;;;
  6. ;;; This program is free software; you can redistribute it and/or
  7. ;;; modify it under the terms of the GNU Lesser General Public License
  8. ;;; as published by the Free Software Foundation; either version 3, or
  9. ;;; (at your option) any later version.
  10. ;;;
  11. ;;; This program is distributed in the hope that it will be useful,
  12. ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU Lesser General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU Lesser General Public
  17. ;;; License along with this software; see the file COPYING.LESSER. If
  18. ;;; not, write to the Free Software Foundation, Inc., 51 Franklin
  19. ;;; Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. (define-module (benchmarks bytevector)
  21. #:use-module (rnrs bytevectors)
  22. #:use-module (srfi srfi-4)
  23. #:use-module (benchmark-suite lib))
  24. (define bv (make-bytevector 16384))
  25. (define %native-endianness
  26. (native-endianness))
  27. (define %foreign-endianness
  28. (if (eq? (native-endianness) (endianness little))
  29. (endianness big)
  30. (endianness little)))
  31. (define u8v (make-u8vector 16384))
  32. (define u16v (make-u16vector 8192))
  33. (define u32v (make-u32vector 4196))
  34. (define u64v (make-u64vector 2048))
  35. (with-benchmark-prefix "ref/set!"
  36. (benchmark "bytevector-u8-ref" 1000000
  37. (bytevector-u8-ref bv 0))
  38. (benchmark "bytevector-u16-ref (foreign)" 1000000
  39. (bytevector-u16-ref bv 0 %foreign-endianness))
  40. (benchmark "bytevector-u16-ref (native)" 1000000
  41. (bytevector-u16-ref bv 0 %native-endianness))
  42. (benchmark "bytevector-u16-native-ref" 1000000
  43. (bytevector-u16-native-ref bv 0))
  44. (benchmark "bytevector-u32-ref (foreign)" 1000000
  45. (bytevector-u32-ref bv 0 %foreign-endianness))
  46. (benchmark "bytevector-u32-ref (native)" 1000000
  47. (bytevector-u32-ref bv 0 %native-endianness))
  48. (benchmark "bytevector-u32-native-ref" 1000000
  49. (bytevector-u32-native-ref bv 0))
  50. (benchmark "bytevector-u64-ref (foreign)" 1000000
  51. (bytevector-u64-ref bv 0 %foreign-endianness))
  52. (benchmark "bytevector-u64-ref (native)" 1000000
  53. (bytevector-u64-ref bv 0 %native-endianness))
  54. (benchmark "bytevector-u64-native-ref" 1000000
  55. (bytevector-u16-native-ref bv 0)))
  56. (with-benchmark-prefix "lists"
  57. (benchmark "bytevector->u8-list" 2000
  58. (bytevector->u8-list bv))
  59. (benchmark "bytevector->uint-list 16-bit" 2000
  60. (bytevector->uint-list bv (native-endianness) 2))
  61. (benchmark "bytevector->uint-list 64-bit" 2000
  62. (bytevector->uint-list bv (native-endianness) 8)))
  63. (with-benchmark-prefix "SRFI-4" ;; for comparison
  64. (benchmark "u8vector-ref" 1000000
  65. (u8vector-ref u8v 0))
  66. (benchmark "u16vector-ref" 1000000
  67. (u16vector-ref u16v 0))
  68. (benchmark "u32vector-ref" 1000000
  69. (u32vector-ref u32v 0))
  70. (benchmark "u64vector-ref" 1000000
  71. (u64vector-ref u64v 0)))