/mobile Handheld Friendly website

 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.470.4718,628585  0% 96% 4% 4%
4,0005.685.6818,628585  1% 0% 1% 100%
16,00088.0488.0320,252585  0% 1% 100% 0%

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.

 notes

Welcome to Racket v6.0.

 mandelbrot Racket #2 program source code

#lang racket/base

;;; The Computer Language Benchmarks Game
;;; http://benchmarksgame.alioth.debian.org/
;;
;;; Derived from the Chicken Scheme variant by Anthony Borla
;;; contributed by Matthew Flatt
;;
;; This version uses unsafe operations

(require racket/cmdline
	 racket/require (for-syntax racket/base)
	 (filtered-in
	  (lambda (name) (regexp-replace #rx"unsafe-" name ""))
	  racket/unsafe/ops))

(define +limit-sqr+ 4.0)

(define +iterations+ 50)

;; -------------------------------

(define (mandelbrot x y n ci)
  (let ((cr (fl- (fl/ (fl* 2.0 (fx->fl x)) (fx->fl n)) 1.5)))
    (let loop ((i 0) (zr 0.0) (zi 0.0))
      (if (fx> i +iterations+)
          1
          (cond
           ((fl> (fl+ (fl* zr zr) (fl* zi zi)) +limit-sqr+) 0)
           (else (loop (fx+ 1 i) 
                       (fl+ (fl- (fl* zr zr) (fl* zi zi)) cr) 
                       (fl+ (fl* 2.0 (fl* zr zi)) ci))))))))

;; -------------------------------

(define (main n)
  (let ((out (current-output-port)))

    (fprintf out "P4\n~a ~a\n" n n)

    (let loop-y ((y 0))

      (when (fx< y n)
        
        (let ([ci (fl- (fl/ (fl* 2.0 (fx->fl y)) (fx->fl n)) 1.0)])
          
          (let loop-x ((x 0) (bitnum 0) (byteacc 0))

            (if (fx< x n)
                (let ([bitnum (fx+ 1 bitnum)]
                      [byteacc (fx+ (fxlshift byteacc 1) 
                                           (mandelbrot x y n ci))])

                  (cond
                   ((fx= bitnum 8)
                    (write-byte byteacc out)
                    (loop-x (fx+ 1 x) 0 0))
                   
                   [else (loop-x (fx+ 1 x) bitnum byteacc)]))

                (begin
                  (when (positive? bitnum)
                    (write-byte (arithmetic-shift byteacc 
                                                  (- 8 (bitwise-and n #x7))) 
                                out))

                  (loop-y (add1 y))))))))))

;; -------------------------------

(command-line #:args (n)
              (main (string->number n)))

 make, command-line, and program output logs

Fri, 28 Feb 2014 08:00:34 GMT

COMMAND LINE:
/usr/local/src/racket-6.0/bin/racket  mandelbrot.racket-2.racket 16000

(BINARY) PROGRAM OUTPUT NOT SHOWN

Revised BSD license

  Home   Conclusions   License   Play