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
5000.340.35272627  0% 0% 3% 100%
3,0006.946.9420,096627  1% 1% 1% 100%
5,50022.9022.9121,800627  0% 1% 0% 100%

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

Read spectral-norm benchmark to see what this program should do.


Welcome to Racket v6.1.1.

 spectral-norm Racket #3 program source code

#lang racket/base
;; The Computer Language Benchmarks Game
;; Translated from Mike Pall's Lua version.
;; Parallelized by Sam Tobin-Hochstadt

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

(define-syntax-rule (for/par k ([i N]) b)  
  (let ([stride (fxquotient N k)])
    (define fs 
      (for/list ([n k])
        (future (λ () (for ([i (in-range (fx* n stride) (fxmin N (fx* (fx+ n 1) stride)))]) b)))))
    (for-each touch fs)))

;; the big let improves performance by about 20%
(let* ()
  (define N (command-line #:args (n) (string->number n)))
  (define C (processor-count))
  (define (A i j)
    (let ([ij (fx+ i j)])
      (fl/ 1.0 (fl+ (fl* (fl* (fx->fl ij)
                              (fx->fl (fx+ ij 1)))
                    (fx->fl (fx+ i 1))))))
  (define (Av x y N)
    (for/par C ([i N])
       y i
       (let L ([a 0.0] [j 0])
         (if (fx= j N) a
             (L (fl+ a (fl* (flvector-ref x j) (A i j)))
                (fx+ j 1)))))))
  (define (Atv x y N)
    (for/par C ([i N])
       y i
       (let L ([a 0.0] [j 0])
         (if (fx= j N) a
             (L (fl+ a (fl* (flvector-ref x j) (A j i)))
                (fx+ j 1)))))))
  (define (AtAv x y t N) (Av x t N) (Atv t y N))
  (define u (make-flvector N 1.0))
  (define v (make-flvector N))
  (define t (make-flvector N))
  (for ([i (in-range 10)])
    (AtAv u v t N) (AtAv v u t N))
  (displayln (real->decimal-string 
               (let L ([vBv 0.0] [vv 0.0] [i 0])
                 (if (fx= i N) (fl/ vBv vv)
                     (let ([ui (flvector-ref u i)] [vi (flvector-ref v i)])
                       (L (fl+ vBv (fl* ui vi))
                          (fl+ vv (fl* vi vi))
                          (fx+ i 1))))))

 make, command-line, and program output logs

Sat, 04 Apr 2015 01:25:19 GMT

/usr/local/src/racket-6.1.1/bin/racket  spectralnorm.racket-3.racket 5500


Revised BSD license

  Home   Conclusions   License   Play