performance measurements

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

 N  CPU secs Elapsed secs Memory KB Code B ≈ CPU Load
5000.280.28220525  4% 7% 0% 100%
3,0009.799.794,676525  0% 1% 1% 100%
5,50032.8932.904,676525  0% 1% 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

rustc 0.11.0 (aa1163b92de7717eb7c5eba002b4012e0574a7fe 2014-06-27 12:50:16 -0700)

 spectral-norm Rust #2 program source code

// The Computer Language Benchmarks Game
// http://benchmarksgame.alioth.debian.org/
//
// contributed by Mikhail Ivko
// algorithm is a copy from Ledrug's C code

use std::from_str::FromStr;
use std::iter::AdditiveIterator;

fn a_elem(i: uint, j: uint) -> f64 {
    1.0 / (((i+j) * (i+j+1) / 2 + i + 1) as f64)
}

fn dot(v: &[f64], u: &[f64]) -> f64 {
    v.iter().zip(u.iter()).map(|(&a, &b)| a*b).sum()
}

fn mult_av(v: &[f64], out: &mut [f64]) {
    for (i, res) in range(0, out.len()).zip(out.mut_iter()) {
        *res = range(0, v.len()).zip(v.iter()).map(|(j, &vval)|
            a_elem(i, j)*vval).sum()
    }
}

fn mult_atv(v: &[f64], out: &mut [f64]) {
    for (i, res) in range(0, out.len()).zip(out.mut_iter()) {
        *res = range(0, v.len()).zip(v.iter()).map(|(j, &vval)|
            a_elem(j, i)*vval).sum()
    }
        
}

fn mult_atav(v: &[f64], out: &mut [f64], tmp: &mut [f64]) {
    mult_av(v, tmp);
    mult_atv(tmp, out);
}

fn main() {
    let args = std::os::args();
    let args = args.as_slice();
    let n = if args.len() < 2 {
        2000
    } else {
        FromStr::from_str(args[1].as_slice()).unwrap()
    };
    let n = if n % 2 != 0 { n + 1 } else { n };

    let mut u = Vec::from_elem(n, 1f64);
    let u = u.as_mut_slice();
    let mut v = Vec::from_elem(n, 0f64);
    let v = v.as_mut_slice();
    let mut tmp = Vec::from_elem(n, 0f64);
    let tmp = tmp.as_mut_slice();

    for _ in range(0, 10u) {
        mult_atav(u, v, tmp);
        mult_atav(v, u, tmp);
    }

    println!("{:.9}", (dot(u, v)/dot(v, v)).sqrt());
}

 make, command-line, and program output logs

Thu, 11 Sep 2014 16:03:47 GMT

MAKE:
/usr/local/src/rust-0.11.0-i686-unknown-linux-gnu/bin/rustc --opt-level=3 spectralnorm.rust-2.rs -o spectralnorm.rust-2.rust_run
rm spectralnorm.rust-2.rs
1.13s to complete and log all make actions

COMMAND LINE:
./spectralnorm.rust-2.rust_run 5500

PROGRAM OUTPUT:
1.274224153

Revised BSD license

  Home   Conclusions   License   Play