summaryrefslogtreecommitdiff
path: root/benchmark-suite/benchmarks/bytevectors.bm
blob: a686a08c9f3391de70e765031441bd519070cd2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
;;; -*- mode: scheme; coding: latin-1; -*-
;;; R6RS Byte Vectors.
;;;
;;; Copyright 2009  Ludovic Courtès <ludo@gnu.org>
;;;
;;;
;;; 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 bytevector)
  :use-module (rnrs bytevector)
  :use-module (srfi srfi-4)
  :use-module (benchmark-suite lib))

(define bv (make-bytevector 16384))

(define %native-endianness
  (native-endianness))

(define %foreign-endianness
  (if (eq? (native-endianness) (endianness little))
      (endianness big)
      (endianness little)))

(define u8v  (make-u8vector 16384))
(define u16v (make-u16vector 8192))
(define u32v (make-u32vector 4196))
(define u64v (make-u64vector 2048))


(with-benchmark-prefix "ref/set!"

  (benchmark "bytevector-u8-ref" 1000000
    (bytevector-u8-ref bv 0))

  (benchmark "bytevector-u16-ref (foreign)" 1000000
    (bytevector-u16-ref bv 0 %foreign-endianness))

  (benchmark "bytevector-u16-ref (native)" 1000000
    (bytevector-u16-ref bv 0 %native-endianness))

  (benchmark "bytevector-u16-native-ref" 1000000
    (bytevector-u16-native-ref bv 0))

  (benchmark "bytevector-u32-ref (foreign)" 1000000
    (bytevector-u32-ref bv 0 %foreign-endianness))

  (benchmark "bytevector-u32-ref (native)" 1000000
    (bytevector-u32-ref bv 0 %native-endianness))

  (benchmark "bytevector-u32-native-ref" 1000000
    (bytevector-u32-native-ref bv 0))

  (benchmark "bytevector-u64-ref (foreign)" 1000000
    (bytevector-u64-ref bv 0 %foreign-endianness))

  (benchmark "bytevector-u64-ref (native)" 1000000
    (bytevector-u64-ref bv 0 %native-endianness))

  (benchmark "bytevector-u64-native-ref" 1000000
    (bytevector-u16-native-ref bv 0)))


(with-benchmark-prefix "lists"

  (benchmark "bytevector->u8-list" 2000
    (bytevector->u8-list bv))

  (benchmark "bytevector->uint-list 16-bit" 2000
    (bytevector->uint-list bv (native-endianness) 2))

  (benchmark "bytevector->uint-list 64-bit" 2000
    (bytevector->uint-list bv (native-endianness) 8)))


(with-benchmark-prefix "SRFI-4" ;; for comparison

  (benchmark "u8vector-ref" 1000000
    (u8vector-ref u8v 0))

  (benchmark "u16vector-ref" 1000000
    (u16vector-ref u16v 0))

  (benchmark "u32vector-ref" 1000000
    (u32vector-ref u32v 0))

  (benchmark "u64vector-ref" 1000000
    (u64vector-ref u64v 0)))