1 ;;; subr.bm --- Measure the subr invocation cost. -*- Scheme -*-
3 ;;; Copyright (C) 2009 Free Software Foundation, Inc.
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.
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 Lesser General Public License for more details.
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
20 (define-module (benchmarks subrs)
21 :use-module (benchmark-suite lib))
24 (define hook1 (make-hook 1))
25 (define hook3 (make-hook 3))
27 (with-benchmark-prefix "subr invocation"
29 (benchmark "simple subr" 700000
30 ;; 1 required argument, 0 optional arguments, no rest.
33 (benchmark "generic subr" 700000
34 ;; 2 required arguments, 4 optional arguments, no rest.
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"))
42 (benchmark "generic subr with rest arg" 700000
43 ;; 1 required argument, 0 optional arguments, 1 rest.
46 (benchmark "generic subr with rest arg and 3+ parameters" 700000
47 ;; 1 required argument, 0 optional arguments, 1 rest.
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)))
54 (with-benchmark-prefix "subr application"
56 (benchmark "simple subr" 700000
59 (benchmark "generic subr" 700000
60 (apply string= "foo" '("bar")))
62 (benchmark "generic subr with rest arg" 700000
63 (apply run-hook hook1 '(1)))
65 (benchmark "generic subr with rest arg and 3+ parameters" 700000
66 (run-hook hook3 1 2 '(3))))