aboutsummaryrefslogtreecommitdiffstats
path: root/bench.scm
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2017-02-20 00:05:23 -0800
committerBryan Newbold <bnewbold@robocracy.org>2017-02-20 00:05:23 -0800
commit5ca6e8e6a4e5c022a6fb5d28f30219c22c99eda8 (patch)
tree9b744b9dbf39e716e56daa620e2f3041968caf19 /bench.scm
downloadscm-5ca6e8e6a4e5c022a6fb5d28f30219c22c99eda8.tar.gz
scm-5ca6e8e6a4e5c022a6fb5d28f30219c22c99eda8.zip
Import Upstream version 4e6upstream/4e6
Diffstat (limited to 'bench.scm')
-rw-r--r--bench.scm55
1 files changed, 55 insertions, 0 deletions
diff --git a/bench.scm b/bench.scm
new file mode 100644
index 0000000..acb4a2c
--- /dev/null
+++ b/bench.scm
@@ -0,0 +1,55 @@
+
+(require (in-vicinity (implementation-vicinity) "pi.scm"))
+(require 'transcript)
+(define isqrt
+ (cond ((provided? 'inexact) sqrt)
+ (else (require 'root) integer-sqrt)))
+(define i/
+ (cond ((provided? 'inexact) /)
+ (else quotient)))
+(define around
+ (cond ((provided? 'inexact)
+ (lambda (x)
+ (cond ((>= 3000 (abs x) 3) (inexact->exact (round x)))
+ (else x))))
+ (else identity)))
+
+(define (time-pi digits)
+ (let ((start-time (get-internal-run-time)))
+ (pi digits 4)
+ (i/ (* 1000 (- (get-internal-run-time) start-time))
+ internal-time-units-per-second)))
+
+(define (benchmark . arg)
+ (define file
+ (cond ((null? arg) "bench.log")
+ (else (car arg))))
+ (do ((digits 50 (+ digits digits))
+ (t 0 (time-pi (+ digits digits))))
+ ((> t 3000)
+ (do ((tl '() (cons (time-pi digits) tl))
+ (j 12 (+ -1 j)))
+ ((zero? j)
+ (let* ((avg (i/ (apply + tl) (length tl)))
+ (dev (isqrt (i/ (apply
+ + (map (lambda (x) (* (- x avg) (- x avg)))
+ tl))
+ (length tl)))))
+ (and file (transcript-on file))
+ (for-each display
+ (list digits " digits took " (around avg) " mSec +/- "
+ (around dev) " mSec."))
+ (newline)
+ (let ((scaled-avg (i/ (* (i/ (* avg 1000) digits) 1000) digits)))
+ (for-each display
+ (list " That is about " scaled-avg
+ " mSec/k-digit^2 +/- "
+ (around
+ (i/ (* 100 (i/ (* (i/ (* dev 1000) digits)
+ 1000) digits))
+ scaled-avg))
+ "%."))
+ (newline)
+ (and file (transcript-off)))
+ ))))))
+(benchmark)