1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-01 04:10:18 +02:00

Augment `arithmetic.bm'.

* benchmark-suite/benchmarks/arithmetic.bm (repeat): Change the syntax.
  Add support for binary OP.
  ("fixnum")["1+", "1-"]: Adjust accordingly.
  ["+", "-"]: New benchmarks.
This commit is contained in:
Ludovic Courtès 2010-10-27 23:28:58 +02:00
parent 0b9bdb1b57
commit 9cec275968

View file

@ -23,13 +23,22 @@
(define-syntax repeat (define-syntax repeat
(lambda (s) (lambda (s)
;; Construct an expression of the form `(OP (OP (OP BODY)))', with a ;; Construct an expression of the form `(OP (OP (OP SEED)))', with a
;; depth of COUNT. ;; depth of COUNT.
(syntax-case s () (syntax-case s (<>)
((_ op body count) ((_ (op x <>) seed count) ;; binary OP
(number? (syntax->datum #'count)) (number? (syntax->datum #'count))
(let loop ((count (syntax->datum #'count)) (let loop ((count (syntax->datum #'count))
(result #'body)) (result #'seed))
(if (= 0 count)
result
(loop (1- count)
(with-syntax ((result result))
#'(op x result))))))
((_ (op <>) seed count) ;; unary OP
(number? (syntax->datum #'count))
(let loop ((count (syntax->datum #'count))
(result #'seed))
(if (= 0 count) (if (= 0 count)
result result
(loop (1- count) (loop (1- count)
@ -40,7 +49,13 @@
(with-benchmark-prefix "fixnum" (with-benchmark-prefix "fixnum"
(benchmark "1+" 1e7 (benchmark "1+" 1e7
(repeat 1+ 2 100)) (repeat (1+ <>) 2 100))
(benchmark "1-" 1e7 (benchmark "1-" 1e7
(repeat 1- 2 100))) (repeat (1- <>) 2 100))
(benchmark "+" 1e7
(repeat (+ 2 <>) 7 100))
(benchmark "-" 1e7
(repeat (+ 2 <>) 7 100)))