From 1dc963684b5d26ae09079a10bc25603840d1bed3 Mon Sep 17 00:00:00 2001 From: Vincent St-Amour Date: Thu, 17 Jun 2010 16:32:53 -0400 Subject: [PATCH] Rewrote the typed partialsums benchmark to be closer to the untyped version. --- .../shootout/typed/partialsums.rktl | 51 +++++++++---------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/collects/tests/racket/benchmarks/shootout/typed/partialsums.rktl b/collects/tests/racket/benchmarks/shootout/typed/partialsums.rktl index c14211af07..25f9bd5b96 100644 --- a/collects/tests/racket/benchmarks/shootout/typed/partialsums.rktl +++ b/collects/tests/racket/benchmarks/shootout/typed/partialsums.rktl @@ -8,25 +8,24 @@ ;; Contributed by Anthony Borla ;; --------------------------------------------------------------------- -(require scheme/cmdline) -(require scheme/flonum) +(require racket/cmdline) -(let ((n (exact->inexact (assert (string->number (command-line #:args (n) (assert n string?))))))) +(let ((n (exact->inexact (assert (string->number (assert (command-line #:args (n) n) string?)))))) (let: loop : Void - ([d : Integer 0] - (alt : Float 1.0) (d2 : Integer 0) (d3 : Integer 0) - (ds : Real 0.0) (dc : Real 0.0) - (s0 : Float 0.0) (s1 : Float 0.0) (s2 : Float 0.0) + ([d : Float 0.0] + (alt : Integer 1) (d2 : Float 0.0) (d3 : Float 0.0) + (ds : Float 0.0) (dc : Float 0.0) + (s0 : Complex 0) (s1 : Complex 0) (s2 : Float 0.0) (s3 : Float 0.0) (s4 : Float 0.0) (s5 : Float 0.0) (s6 : Float 0.0) (s7 : Float 0.0) (s8 : Float 0.0)) (if (= d n) (let ([format-result - (lambda: ((str : String) (n : Float)) + (lambda: ((str : String) (n : Real)) (printf str (real->decimal-string n 9)))]) - (format-result "~a\t(2/3)^k\n" s0) - (format-result "~a\tk^-0.5\n" s1) + (format-result "~a\t(2/3)^k\n" (assert s0 real?)) + (format-result "~a\tk^-0.5\n" (assert s1 real?)) (format-result "~a\t1/k(k+1)\n" s2) (format-result "~a\tFlint Hills\n" s3) (format-result "~a\tCookson Hills\n" s4) @@ -35,22 +34,22 @@ (format-result "~a\tAlternating Harmonic\n" s7) (format-result "~a\tGregory\n" s8)) - (let*: ((d : Integer (+ d 1)) - (d2 : Integer (* d d)) - (d3 : Integer (* d2 d)) - (ds : Real (sin d)) - (dc : Real (cos d)) - - (s0 : Float (+ s0 (exact->inexact (expt (/ 2.0 3.0) (- d 1))))) - (s1 : Float (+ s1 (/ 1 (flsqrt (exact->inexact d))))) - (s2 : Float (+ s2 (/ 1 (* d (+ d 1))))) - (s3 : Float (+ s3 (/ 1 (* d3 (* ds ds))))) - (s4 : Float (+ s4 (/ 1 (* d3 (* dc dc))))) - (s5 : Float (+ s5 (/ 1 d))) - (s6 : Float (+ s6 (/ 1 d2))) - (s7 : Float (+ s7 (/ alt d))) - (s8 : Float (+ s8 (/ alt (- (* 2 d) 1)))) - (alt : Float (- alt))) + (let* ((d (+ d 1)) + (d2 (* d d)) + (d3 (* d2 d)) + (ds (sin d)) + (dc (cos d)) + + (s0 (+ s0 (expt (/ 2.0 3) (- d 1)))) + (s1 (+ s1 (/ 1 (sqrt d)))) + (s2 (+ s2 (/ 1 (* d (+ d 1))))) + (s3 (+ s3 (/ 1 (* d3 (* ds ds))))) + (s4 (+ s4 (/ 1 (* d3 (* dc dc))))) + (s5 (+ s5 (/ 1 d))) + (s6 (+ s6 (/ 1 d2))) + (s7 (+ s7 (/ alt d))) + (s8 (+ s8 (/ alt (- (* 2 d) 1)))) + (alt (- alt))) (loop d alt d2 d3 ds dc