From eec0f4bf665a041a76fdde7054e22844b4e99b35 Mon Sep 17 00:00:00 2001 From: Eli Barzilay Date: Sun, 20 Jun 2010 18:28:56 -0400 Subject: [PATCH] Yet another 2x factor. (Total ~22x.) --- .../racket/benchmarks/shootout/fasta.rkt | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/collects/tests/racket/benchmarks/shootout/fasta.rkt b/collects/tests/racket/benchmarks/shootout/fasta.rkt index 7943593fac..f3ca189bbe 100644 --- a/collects/tests/racket/benchmarks/shootout/fasta.rkt +++ b/collects/tests/racket/benchmarks/shootout/fasta.rkt @@ -92,15 +92,27 @@ (bytes-set! buf n (bytes-ref lookup-byte R)) (loop (fx+ n 1) R)) (begin (write-bytes buf out 0 (fx+ to 1)) R)))) - (define buf (make-bytes (add1 line-length))) + (define (make-line R) + (let ([buf (make-bytes (fx+ line-length 1))]) + (bytes-set! buf line-length LF) + (let loop ([n 0] [R R]) + (if (fx< n line-length) + (let ([R (random-next R)]) + (bytes-set! buf n (bytes-ref lookup-byte R)) + (loop (fx+ n 1) R)) + (cons buf R))))) (define LF (char->integer #\newline)) + (define buf (make-bytes (fx+ line-length 1))) + (define-values (full-lines last) (quotient/remainder N line-length)) + (define/IM (chunk r) (make-line r)) (bytes-set! buf line-length LF) (display header out) - (let-values ([(full-lines last) (quotient/remainder N line-length)]) - (let loop ([i full-lines] [R R]) - (cond [(fx> i 0) (loop (fx- i 1) (n-randoms line-length R))] - [(fx> last 0) (bytes-set! buf last LF) (n-randoms last R)] - [else R])))) + (let loop ([i full-lines] [R R]) + (cond [(fx> i 0) (let ([c (chunk R)]) + (write-bytes (car c)) + (loop (fx- i 1) (cdr c)))] + [(fx> last 0) (bytes-set! buf last LF) (n-randoms last R)] + [else R]))) ;; ----------------------------------------