1 ;;; -*- mode: scheme; coding: latin-1; -*-
4 ;;; Copyright 2009 Ludovic Courtès <ludo@gnu.org>
7 ;;; This program is free software; you can redistribute it and/or modify
8 ;;; it under the terms of the GNU General Public License as published by
9 ;;; the Free Software Foundation; either version 2 of the License, or
10 ;;; (at your option) any later version.
12 ;;; This program is distributed in the hope that it will be useful,
13 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;;; GNU General Public License for more details.
17 ;;; You should have received a copy of the GNU General Public License
18 ;;; along with this program; if not, write to the Free Software
19 ;;; Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 (define-module (benchmarks bytevector)
22 :use-module (rnrs bytevector)
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)))