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.35280627  3% 0% 3% 100%
3,0006.956.9618,828627  1% 1% 2% 100%
5,50023.0823.0919,560627  0% 0% 1% 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.

 notes

Welcome to Racket v6.0.

 spectral-norm Racket #3 program source code

#lang racket/base
;; The Computer Language Benchmarks Game
;; http://benchmarksgame.alioth.debian.org/
;; 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 ""))
                      racket/unsafe/ops)
         (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)))
                         0.5) 
                    (fx->fl (fx+ i 1))))))
  (define (Av x y N)
    (for/par C ([i N])
      (flvector-set!
       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])
      (flvector-set!
       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 
              (flsqrt 
               (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))))))
              9)))

 make, command-line, and program output logs

Fri, 28 Feb 2014 06:14:23 GMT

COMMAND LINE:
/usr/local/src/racket-6.0/bin/racket  spectralnorm.racket-3.racket 5500

PROGRAM OUTPUT:
1.274224153

Revised BSD license

  Home   Conclusions   License   Play