degenerate let forms
[bpt/guile.git] / benchmark-suite / benchmarks / bytevectors.bm
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
21 (define-module (benchmarks bytevector)
22 #:use-module (rnrs bytevectors)
23 #:use-module (srfi srfi-4)
24 #:use-module (benchmark-suite lib))
25
26 (define bv (make-bytevector 16384))
27
28 (define %native-endianness
29 (native-endianness))
30
31 (define %foreign-endianness
32 (if (eq? (native-endianness) (endianness little))
33 (endianness big)
34 (endianness little)))
35
36 (define u8v (make-u8vector 16384))
37 (define u16v (make-u16vector 8192))
38 (define u32v (make-u32vector 4196))
39 (define u64v (make-u64vector 2048))
40
41 \f
42 (with-benchmark-prefix "ref/set!"
43
44 (benchmark "bytevector-u8-ref" 1000000
45 (bytevector-u8-ref bv 0))
46
47 (benchmark "bytevector-u16-ref (foreign)" 1000000
48 (bytevector-u16-ref bv 0 %foreign-endianness))
49
50 (benchmark "bytevector-u16-ref (native)" 1000000
51 (bytevector-u16-ref bv 0 %native-endianness))
52
53 (benchmark "bytevector-u16-native-ref" 1000000
54 (bytevector-u16-native-ref bv 0))
55
56 (benchmark "bytevector-u32-ref (foreign)" 1000000
57 (bytevector-u32-ref bv 0 %foreign-endianness))
58
59 (benchmark "bytevector-u32-ref (native)" 1000000
60 (bytevector-u32-ref bv 0 %native-endianness))
61
62 (benchmark "bytevector-u32-native-ref" 1000000
63 (bytevector-u32-native-ref bv 0))
64
65 (benchmark "bytevector-u64-ref (foreign)" 1000000
66 (bytevector-u64-ref bv 0 %foreign-endianness))
67
68 (benchmark "bytevector-u64-ref (native)" 1000000
69 (bytevector-u64-ref bv 0 %native-endianness))
70
71 (benchmark "bytevector-u64-native-ref" 1000000
72 (bytevector-u16-native-ref bv 0)))
73
74 \f
75 (with-benchmark-prefix "lists"
76
77 (benchmark "bytevector->u8-list" 2000
78 (bytevector->u8-list bv))
79
80 (benchmark "bytevector->uint-list 16-bit" 2000
81 (bytevector->uint-list bv (native-endianness) 2))
82
83 (benchmark "bytevector->uint-list 64-bit" 2000
84 (bytevector->uint-list bv (native-endianness) 8)))
85
86 \f
87 (with-benchmark-prefix "SRFI-4" ;; for comparison
88
89 (benchmark "u8vector-ref" 1000000
90 (u8vector-ref u8v 0))
91
92 (benchmark "u16vector-ref" 1000000
93 (u16vector-ref u16v 0))
94
95 (benchmark "u32vector-ref" 1000000
96 (u32vector-ref u32v 0))
97
98 (benchmark "u64vector-ref" 1000000
99 (u64vector-ref u64v 0)))