/mobile Handheld Friendly website
x64 Ubuntu : Intel® Q6600® quad-core |
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 |
|---|---|---|---|---|---|
| 500 | 0.45 | 0.45 | 19,780 | 532 | 0% 2% 0% 100% |
| 3,000 | 11.35 | 11.35 | 20,212 | 532 | 59% 41% 0% 0% |
| 5,500 | 37.83 | 37.83 | 20,816 | 532 | 0% 0% 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 v5.3.4.
#lang racket/base ;;; The Computer Language Benchmarks Game ;;; http://benchmarksgame.alioth.debian.org/ ;;; Translated directly from the C# version by Isaac Gouy ;;; contributed by Matthew Flatt ;; This version uses unsafe operations (require racket/cmdline racket/require (for-syntax racket/base) (rename-in (filtered-in (lambda (name) (regexp-replace #rx"unsafe-" name "")) racket/unsafe/ops) [fx->fl ->fl]) (only-in racket/flonum make-flvector)) (define (Approximate n) (let ([u (make-flvector n 1.0)] [v (make-flvector n 0.0)]) ;; 20 steps of the power method (for ([i (in-range 10)]) (MultiplyAtAv n u v) (MultiplyAtAv n v u)) ;; B=AtA A multiplied by A transposed ;; v.Bv /(v.v) eigenvalue of v (let loop ([i 0][vBv 0.0][vv 0.0]) (if (= i n) (flsqrt (fl/ vBv vv)) (let ([vi (flvector-ref v i)]) (loop (add1 i) (fl+ vBv (fl* (flvector-ref u i) vi)) (fl+ vv (fl* vi vi)))))))) ;; return element i,j of infinite matrix A (define (A i j) (fl/ 1.0 (fl+ (fl* (->fl (+ i j)) (fl/ (->fl (+ i (+ j 1))) 2.0)) (->fl (+ i 1))))) ;; multiply vector v by matrix A (define (MultiplyAv n v Av) (for ([i (in-range n)]) (flvector-set! Av i (for/fold ([r 0.0]) ([j (in-range n)]) (fl+ r (fl* (A i j) (flvector-ref v j))))))) ;; multiply vector v by matrix A transposed (define (MultiplyAtv n v Atv) (for ([i (in-range n)]) (flvector-set! Atv i (for/fold ([r 0.0]) ([j (in-range n)]) (fl+ r (fl* (A j i) (flvector-ref v j))))))) ;; multiply vector v by matrix A and then by matrix A transposed (define (MultiplyAtAv n v AtAv) (let ([u (make-flvector n 0.0)]) (MultiplyAv n v u) (MultiplyAtv n u AtAv))) (printf "~a\n" (real->decimal-string (Approximate (command-line #:args (n) (string->number n))) 9))
Sat, 11 May 2013 17:28:41 GMT COMMAND LINE: /usr/local/src/racket-5.3.4/bin/racket spectralnorm.racket-2.racket 5500 PROGRAM OUTPUT: 1.274224153