Merge commit '47ca15c7dffd14a82e75c1a0aeeaf2e77f3fa5b4'
[bpt/guile.git] / benchmark-suite / benchmarks / subr.bm
CommitLineData
b786a5bb
LC
1;;; subr.bm --- Measure the subr invocation cost. -*- Scheme -*-
2;;;
3;;; Copyright (C) 2009 Free Software Foundation, Inc.
4;;;
53befeb7
NJ
5;;; This program is free software; you can redistribute it and/or
6;;; modify it under the terms of the GNU Lesser General Public License
7;;; as published by the Free Software Foundation; either version 3, or
8;;; (at your option) any later version.
b786a5bb
LC
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
53befeb7 13;;; GNU Lesser General Public License for more details.
b786a5bb 14;;;
53befeb7
NJ
15;;; You should have received a copy of the GNU Lesser General Public
16;;; License along with this software; see the file COPYING.LESSER. If
17;;; not, write to the Free Software Foundation, Inc., 51 Franklin
18;;; Street, Fifth Floor, Boston, MA 02110-1301 USA
b786a5bb
LC
19
20(define-module (benchmarks subrs)
21 :use-module (benchmark-suite lib))
22
23\f
3e414c30
LC
24(define hook1 (make-hook 1))
25(define hook3 (make-hook 3))
26
b786a5bb
LC
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".
3e414c30
LC
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)))
b786a5bb
LC
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
3e414c30
LC
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))))