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
500Make Error  898   

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.


rustc 1.1.0 (35ceea399 2015-06-19)

 spectral-norm Rust program source code

// The Computer Language Benchmarks Game
// contributed by the Rust Project Developers
// contributed by TeXitoi

#![feature(os, core, env)]


use std::iter::{repeat, AdditiveIterator};
use std::thread;
use std::num::Float;
use std::os;
use std::simd::f64x2;

fn main() {
    let n = std::env::args_os().nth(1)
        .and_then(|s| s.into_string().ok())
        .and_then(|n| n.parse().ok())
    let answer = spectralnorm(n);
    println!("{:.9}", answer);

fn spectralnorm(n: usize) -> f64 {
    assert!(n % 2 == 0, "only even lengths are accepted");
    let mut u = repeat(1.0).take(n).collect::<Vec<_>>();
    let mut v = u.clone();
    let mut tmp = v.clone();
    for _ in 0..10 {
        mult_AtAv(&u, &mut v, &mut tmp);
        mult_AtAv(&v, &mut u, &mut tmp);
    (dot(&u, &v) / dot(&v, &v)).sqrt()

fn mult_AtAv(v: &[f64], out: &mut [f64], tmp: &mut [f64]) {
    mult_Av(v, tmp);
    mult_Atv(tmp, out);

fn mult_Av(v: &[f64], out: &mut [f64]) {
    parallel(out, |start, out| mult(v, out, start, |i, j| A(i, j)));

fn mult_Atv(v: &[f64], out: &mut [f64]) {
    parallel(out, |start, out| mult(v, out, start, |i, j| A(j, i)));

fn mult<F>(v: &[f64], out: &mut [f64], start: usize, a: F)
           where F: Fn(usize, usize) -> f64 {
    for (i, slot) in out.iter_mut().enumerate().map(|(i, s)| (i + start, s)) {
        let mut sum = f64x2(0.0, 0.0);
        for (j, chunk) in v.chunks(2).enumerate().map(|(j, s)| (2 * j, s)) {
            let top = f64x2(chunk[0], chunk[1]);
            let bot = f64x2(a(i, j), a(i, j + 1));
            sum += top / bot;
        let f64x2(a, b) = sum;
        *slot = a + b;

fn A(i: usize, j: usize) -> f64 {
    ((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()

// Executes a closure in parallel over the given mutable slice. The closure `f`
// is run in parallel and yielded the starting index within `v` as well as a
// sub-slice of `v`.
fn parallel<'a,T, F>(v: &mut [T], ref f: F)
                  where T: Send + Sync + 'a,
                        F: Fn(usize, &mut [T]) + Sync + 'a {
    let size = v.len() / os::num_cpus() + 1;
    v.chunks_mut(size).enumerate().map(|(i, chunk)| {
        thread::scoped(move|| {
            f(i * size, chunk)

 make, command-line, and program output logs

Fri, 26 Jun 2015 02:41:10 GMT

/usr/local/src/rust-1.1.0-x86_64-unknown-linux-gnu/rustc/bin/rustc -C opt-level=3 -C target-cpu=core2 -C lto -o spectralnorm.rust_run 11:41 error: unresolved import `std::iter::AdditiveIterator`. There is no `AdditiveIterator` in `std::iter` use std::iter::{repeat, AdditiveIterator};
                                           ^~~~~~~~~~~~~~~~ 13:20 error: unresolved import `std::num::Float`. There is no `Float` in `std::num` use std::num::Float;
error: aborting due to 2 previous errors
/home/dunham/benchmarksgame/nanobench/makefiles/u64q.programs.Makefile:627: recipe for target 'spectralnorm.rust_run' failed
make: [spectralnorm.rust_run] Error 101 (ignored)
0.10s to complete and log all make actions

./spectralnorm.rust_run 500


Revised BSD license

  Home   Conclusions   License   Play