1 ;;; -*- mode: scheme; coding: iso-8859-1; -*-
4 ;;; Copyright 2009, 2010 Free Software Foundation, Inc.
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.
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.
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
21 (define-module (benchmarks bytevector)
22 #:use-module (rnrs bytevectors)
23 #:use-module (srfi srfi-4)
24 #:use-module (benchmark-suite lib))
26 (define bv (make-bytevector 16384))
28 (define %native-endianness
31 (define %foreign-endianness
32 (if (eq? (native-endianness) (endianness little))
36 (define u8v (make-u8vector 16384))
37 (define u16v (make-u16vector 8192))
38 (define u32v (make-u32vector 4196))
39 (define u64v (make-u64vector 2048))
42 (with-benchmark-prefix "ref/set!"
44 (benchmark "bytevector-u8-ref" 1000000
45 (bytevector-u8-ref bv 0))
47 (benchmark "bytevector-u16-ref (foreign)" 1000000
48 (bytevector-u16-ref bv 0 %foreign-endianness))
50 (benchmark "bytevector-u16-ref (native)" 1000000
51 (bytevector-u16-ref bv 0 %native-endianness))
53 (benchmark "bytevector-u16-native-ref" 1000000
54 (bytevector-u16-native-ref bv 0))
56 (benchmark "bytevector-u32-ref (foreign)" 1000000
57 (bytevector-u32-ref bv 0 %foreign-endianness))
59 (benchmark "bytevector-u32-ref (native)" 1000000
60 (bytevector-u32-ref bv 0 %native-endianness))
62 (benchmark "bytevector-u32-native-ref" 1000000
63 (bytevector-u32-native-ref bv 0))
65 (benchmark "bytevector-u64-ref (foreign)" 1000000
66 (bytevector-u64-ref bv 0 %foreign-endianness))
68 (benchmark "bytevector-u64-ref (native)" 1000000
69 (bytevector-u64-ref bv 0 %native-endianness))
71 (benchmark "bytevector-u64-native-ref" 1000000
72 (bytevector-u16-native-ref bv 0)))
75 (with-benchmark-prefix "lists"
77 (benchmark "bytevector->u8-list" 2000
78 (bytevector->u8-list bv))
80 (benchmark "bytevector->uint-list 16-bit" 2000
81 (bytevector->uint-list bv (native-endianness) 2))
83 (benchmark "bytevector->uint-list 64-bit" 2000
84 (bytevector->uint-list bv (native-endianness) 8)))
87 (with-benchmark-prefix "SRFI-4" ;; for comparison
89 (benchmark "u8vector-ref" 1000000
92 (benchmark "u16vector-ref" 1000000
93 (u16vector-ref u16v 0))
95 (benchmark "u32vector-ref" 1000000
96 (u32vector-ref u32v 0))
98 (benchmark "u64vector-ref" 1000000
99 (u64vector-ref u64v 0)))