]> git.donarmstrong.com Git - lilypond.git/blob - guile18/benchmark-suite/benchmarks/subr.bm
New upstream version 2.19.65
[lilypond.git] / guile18 / benchmark-suite / benchmarks / subr.bm
1 ;;; subr.bm --- Measure the subr invocation cost.     -*- Scheme -*-
2 ;;;
3 ;;; Copyright (C) 2009 Free Software Foundation, Inc.
4 ;;;
5 ;;; This program is free software; you can redistribute it and/or modify
6 ;;; it under the terms of the GNU General Public License as published by
7 ;;; the Free Software Foundation; either version 2, or (at your option)
8 ;;; any later version.
9 ;;;
10 ;;; This program is distributed in the hope that it will be useful,
11 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 ;;; GNU General Public License for more details.
14 ;;;
15 ;;; You should have received a copy of the GNU General Public License
16 ;;; along with this software; see the file COPYING.  If not, write to
17 ;;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 ;;; Boston, MA 02110-1301 USA
19
20 (define-module (benchmarks subrs)
21   :use-module (benchmark-suite lib))
22
23 \f
24 (define hook1 (make-hook 1))
25 (define hook3 (make-hook 3))
26
27 (with-benchmark-prefix "subr invocation"
28
29   (benchmark "simple subr" 700000
30     ;; 1 required argument, 0 optional arguments, no rest.
31     (1+ 0))
32
33   (benchmark "generic subr" 700000
34     ;; 2 required arguments, 4 optional arguments, no rest.
35
36     ;; In Guile 1.8 and earlier, such subrs are implemented as "compiled
37     ;; closures" (cclos).  There, when a cclo/gsubr is called, the evaluator
38     ;; goes through `SCM_APPLY ()' and conses the arguments, which is more
39     ;; costly than the invocation of a "simple subr".
40     (string= "foo" "bar"))
41
42   (benchmark "generic subr with rest arg" 700000
43     ;; 1 required argument, 0 optional arguments, 1 rest.
44     (run-hook hook1 1))
45
46   (benchmark "generic subr with rest arg and 3+ parameters" 700000
47     ;; 1 required argument, 0 optional arguments, 1 rest.
48
49     ;; The evaluator considers calls with 3 and more parameters as a general
50     ;; form and always stores the arguments into a list.
51     (run-hook hook3 1 2 3)))
52
53 \f
54 (with-benchmark-prefix "subr application"
55
56   (benchmark "simple subr" 700000
57     (apply 1+ '(0)))
58
59   (benchmark "generic subr" 700000
60     (apply string= "foo" '("bar")))
61
62   (benchmark "generic subr with rest arg" 700000
63     (apply run-hook hook1 '(1)))
64
65   (benchmark "generic subr with rest arg and 3+ parameters" 700000
66     (run-hook hook3 1 2 '(3))))