subr.bm 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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
  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.
  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 Lesser General Public License for more details.
  14. ;;;
  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
  19. (define-module (benchmarks subrs)
  20. :use-module (benchmark-suite lib))
  21. (define hook1 (make-hook 1))
  22. (define hook3 (make-hook 3))
  23. (with-benchmark-prefix "subr invocation"
  24. (benchmark "simple subr" 700000
  25. ;; 1 required argument, 0 optional arguments, no rest.
  26. (1+ 0))
  27. (benchmark "generic subr" 700000
  28. ;; 2 required arguments, 4 optional arguments, no rest.
  29. ;; In Guile 1.8 and earlier, such subrs are implemented as "compiled
  30. ;; closures" (cclos). There, when a cclo/gsubr is called, the evaluator
  31. ;; goes through `SCM_APPLY ()' and conses the arguments, which is more
  32. ;; costly than the invocation of a "simple subr".
  33. (string= "foo" "bar"))
  34. (benchmark "generic subr with rest arg" 700000
  35. ;; 1 required argument, 0 optional arguments, 1 rest.
  36. (run-hook hook1 1))
  37. (benchmark "generic subr with rest arg and 3+ parameters" 700000
  38. ;; 1 required argument, 0 optional arguments, 1 rest.
  39. ;; The evaluator considers calls with 3 and more parameters as a general
  40. ;; form and always stores the arguments into a list.
  41. (run-hook hook3 1 2 3)))
  42. (with-benchmark-prefix "subr application"
  43. (benchmark "simple subr" 700000
  44. (apply 1+ '(0)))
  45. (benchmark "generic subr" 700000
  46. (apply string= "foo" '("bar")))
  47. (benchmark "generic subr with rest arg" 700000
  48. (apply run-hook hook1 '(1)))
  49. (benchmark "generic subr with rest arg and 3+ parameters" 700000
  50. (run-hook hook3 1 2 '(3))))