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 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)
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.
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
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))))