Changeset 32580 in project


Ignore:
Timestamp:
07/12/15 13:02:55 (5 years ago)
Author:
sjamaan
Message:

numbers: Improve portability of benchmarks. Thanks to Brad Lucier for providing the patch and testing on Gambit

Location:
release/4/numbers/trunk/benchmarks
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • release/4/numbers/trunk/benchmarks/chudnovsky-pi.scm

    r32523 r32580  
    5858                                      ".\n"))))
    5959          '(1 2 3 4 5 6))
     60
  • release/4/numbers/trunk/benchmarks/cl-bench-bignum.scm

    r32570 r32580  
    2222
    2323(cond-expand
    24   ((and chicken (not full-numeric-tower)) (use numbers))
    25   (else #f))
     24 ((and chicken (not full-numeric-tower)) (use numbers))
     25 (else #f))
     26
     27(cond-expand
     28 (gambit (define isqrt integer-sqrt))
     29 (else (define isqrt exact-integer-sqrt)))
     30
     31(cond-expand
     32 (gambit
     33   (define divmod
     34     ;; Nasty workaround to avoid error on ##-prefix in CHICKEN (even though
     35     ;; it's cond-expanded, this doesn't work.
     36     (eval (with-input-from-string
     37             "(let ((q-r (##exact-int.div x y))) (values (car q-r) (cdr q-r)))"
     38             read))))
     39 (chicken (define divmod quotient&remainder))
     40 (else (define (divmod x y) (values (quotient x y) (remainder x y)))))
    2641
    2742(define *x1* #f)
     
    3954       body? ...))))
    4055
    41 (define isqrt exact-integer-sqrt)
    42 ;(define (isqrt x) (exact-integer-nth-root x 2))
    4356
    4457(define pi 3141592653589793/1000000000000000)
     
    5669
    5770;; The new numbers code can do this natively... (floor in CL)
    58 (define (divmod x y) (values (quotient x y) (remainder x y)))
     71;;(define (divmod x y) (values (quotient x y) (remainder x y)))
    5972;;(define divmod quotient&remainder)
    6073
     
    6679  (set! *x2* (isqrt (* 3 (expt 10 (* 2 N)))))
    6780  (set! *x3* (+ (expt 10 N) 1))
    68   ;; (format t "~&~%N = ~D, Multiplication *x1* * *x2*, divide times by ~D~%" N repeat)
    69   (dotimes (count 3)
    70     (dotimes (_ repeat)
    71       (set! *y* (* *x1* *x2*))))
    72   ;; (format t "~&~%N = ~D, Division (with remainder) *x1* / *x2*, divide times by ~D~%" N repeat)
    73   (dotimes (count 3)
    74     (dotimes (_ repeat)
    75       (set!-values (*y* *z*) (divmod *x1* *x2*))))
    76   ;; (format t "~&~%N = ~D, integer_sqrt(*x3*), divide times by ~D~%" N repeat)
    77   (dotimes (count 3)
    78     (dotimes (_ repeat)
    79       (set! *y* (isqrt *x3*))))
    80   ;; (format t "~&~%N = ~D, gcd(*x1*,*x2*), divide times by ~D~%" N repeat)
    81   (dotimes (count 3)
    82     (dotimes (_ repeat)
    83       (set! *y* (gcd *x1* *x2*)))))
     81  (display "N = ") (display N) (display " Multiplication *x1* * *x2*, divide times by ") (display repeat) (newline)
     82  (time (dotimes (count 3)
     83    (dotimes (_ repeat)
     84      (set! *y* (* *x1* *x2*)))))
     85  (display "N = ") (display N) (display " Division (with remainder) *x1* / *x2*, divide times by ") (display repeat) (newline)
     86  (time (dotimes (count 3)
     87           (dotimes (_ repeat)
     88                    (call-with-values
     89                        (lambda ()
     90                          (divmod *x1* *x2*))
     91                      (lambda (y z)
     92                        (set! *y*  y)
     93                        (set! *z* z))))))
     94  (display "N = ") (display N) (display " integer_sqrt(*x3*), divide times by ") (display repeat) (newline)
     95  (time (dotimes (count 3)
     96    (dotimes (_ repeat)
     97      (set! *y* (isqrt *x3*)))))
     98  (display "N = ") (display N) (display " gcd(*x3*), divide times by ") (display repeat) (newline)
     99  (time (dotimes (count 3)
     100    (dotimes (_ repeat)
     101      (set! *y* (gcd *x1* *x2*))))))
    84102
    85103(define (run-elem-100-1000)
     
    127145                      (expt 16 i)))))
    128146    (dotimes (i n)
    129       (set!-values (r p) (truncate-2 p 10))
     147             (call-with-values
     148                 (lambda ()
     149                   (truncate-2 p 10))
     150               (lambda (arg-r arg-p)
     151                 (set! r arg-r)
     152                 (set! p arg-p)))
    130153      (set! dpi (+ (* 10 dpi) r))
    131154      (set! p (* p 10)))
     
    162185    (assert (fuzzy-eql pi (/ api (expt 10 1000))))))
    163186
    164 (print "run-elem-100-1000:")
    165 (time (run-elem-100-1000))
    166 (print "-----------------------------")
    167 (print "run-elem-1000-100:")
    168 (time (run-elem-1000-100))
    169 (print "-----------------------------")
    170 (print "run-elem-10000-1:")
    171 (time (run-elem-10000-1))
    172 (print "-----------------------------")
    173 (print "run-pari-100-10:")
     187(display "run-elem-100-1000:\n")
     188(run-elem-100-1000)
     189(display "-----------------------------\n")
     190(display "run-elem-1000-100:\n")
     191(run-elem-1000-100)
     192(display "-----------------------------\n")
     193(display "run-elem-10000-1:\n")
     194(run-elem-10000-1)
     195(display "-----------------------------\n")
     196(display "run-pari-100-10:\n")
    174197(time (run-pari-100-10))
    175 (print "-----------------------------")
    176 (print "run-pari-200-5:")
     198(display "-----------------------------\n")
     199(display "run-pari-200-5:\n")
    177200(time (run-pari-200-5))
    178 (print "-----------------------------")
    179 (print "run-pi-decimal/small:")
     201(display "-----------------------------\n")
     202(display "run-pi-decimal/small:\n")
    180203(time (dotimes (_ 5) (run-pi-decimal/small)))
    181 (print "-----------------------------")
    182 (print "run-pi-decimal/big:")
     204(display "-----------------------------\n")
     205(display "run-pi-decimal/big:\n")
    183206(time (dotimes (_ 2) (run-pi-decimal/big)))
    184 (print "-----------------------------")
    185 (print "run-pi-pi-atan:")
     207(display "-----------------------------\n")
     208(display "run-pi-pi-atan:\n")
    186209(time (dotimes (_ 200) (run-pi-atan)))
     210
  • release/4/numbers/trunk/benchmarks/frpoly.scm

    r32557 r32580  
    1818;; Using SRFI-55 to attempt to make this at least slightly portable
    1919;; In Scheme48, comment this out and type ,open srfi-39 (or use a package)
    20 (require-extension (srfi 39))
     20(cond-expand
     21 (gambit #t)
     22 (else (require-extension (srfi 39))))
    2123
    2224;; Trivial compat code
     
    274276(print "frpoly for floats:")
    275277(time (dotimes (_ 100) (run-frpoly/float)))
     278
  • release/4/numbers/trunk/benchmarks/pi-ratios.scm

    r32557 r32580  
    4545
    4646;; To get the "error" procedure...
    47 (require-extension (srfi 23))
     47(cond-expand
     48 (gambit #t)
     49 (else (require-extension (srfi 23))))
    4850
    4951;; Not needed for Chicken, but useful for comparison with other implementations
     
    198200(time (dotimes (_ 2) (run-pi-ratios)))
    199201;; EOF
     202
Note: See TracChangeset for help on using the changeset viewer.