performance measurements

Each table row shows performance measurements for this Racket program with a particular command-line input value N.

 N  CPU secs Elapsed secs Memory KB Code B ≈ CPU Load
1,0000.500.5018,780796  0% 49% 22% 100%
4,0005.075.0821,776796  1% 28% 1% 100%
16,00078.1678.1959,040796  0% 0% 0% 100%

Read the ↓ make, command line, and program output logs to see how this program was run.

Read mandelbrot benchmark to see what this program should do.


Welcome to Racket v6.1.1.

 mandelbrot Racket #4 program source code

#lang racket/base

;; The Computer Language Benchmarks Game
;; contributed by Eli Barzilay
;; parallelized by Sam Tobin-Hochstadt

(require racket/require (for-syntax racket/base) racket/future
         (filtered-in (lambda (n) (regexp-replace #rx"unsafe-" n ""))
         (only-in racket/flonum make-flvector)

(define LIMIT-SQR 4.0)
(define ITERATIONS 50)
(define N (command-line #:args (n) (string->number n)))
(define N.0 (fx->fl N))
(define 2/N (fl/ 2.0 N.0))
(define Crs
  (let ([v (make-flvector N)])
    (for ([x (in-range N)])
      (flvector-set! v x (fl- (fl/ (fx->fl (fx* 2 x)) N.0) 1.5)))

(define bpr (ceiling (/ N 8)))
(define bitmap (make-bytes (* N bpr)))

(define-syntax (let-n s)
  (syntax-case s ()
    [(_ N bs E)
     (for/fold ([E #'E]) ([_ (syntax-e #'N)]) #`(let bs #,E))]))

(define-syntax-rule (M Cr Ci)
  (let loop ([i 0] [Zr 0.0] [Zi 0.0])
    (cond [(fl> (fl+ (fl* Zr Zr) (fl* Zi Zi)) LIMIT-SQR) 0]
          [(fx= i ITERATIONS) 1]
          [else (let-n 5 ([Zr (fl+ (fl- (fl* Zr Zr) (fl* Zi Zi)) Cr)]
                          [Zi (fl+ (fl* 2.0 (fl* Zr Zi)) Ci)])
                  (loop (fx+ i 5) Zr Zi))])))

(printf "P4\n~a ~a\n" N N)
 (for/list ([y (in-range N 0 -1)])
    (λ ()
      (define Ci (fl- (fl* 2/N (fx->fl y)) 1.0))
      (let loop-x ([x 0] [bitnum 0] [byteacc 0] [aindex (fx* bpr (fx- N y))])
        (cond [(fx< x N)
               (define Cr (flvector-ref Crs x))
               (define byteacc* (fx+ (fxlshift byteacc 1) (M Cr Ci)))
               (cond [(fx= bitnum 7)
                      (bytes-set! bitmap aindex byteacc*)
                      (loop-x (fx+ x 1) 0 0 (fx+ aindex 1))]
                     [else (loop-x (fx+ x 1) (fx+ bitnum 1) byteacc* aindex)])]
               (when (fx> bitnum 0)
                 (bytes-set! bitmap aindex
                             (fxlshift byteacc (fx- 8 (fxand N #x7)))))]))))))
(void (write-bytes bitmap))

 make, command-line, and program output logs

Sat, 04 Apr 2015 00:21:06 GMT

/usr/local/src/racket-6.1.1/bin/racket  mandelbrot.racket-4.racket 16000


Revised BSD license

  Home   Conclusions   License   Play