Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 74 lines (63 sloc) 1.569 kb
7c8d128 Brian Anderson bench: Add shootout-spectralnorm
brson authored
1 // Based on spectalnorm.gcc by Sebastien Loisel
2
3 use std;
4
5 fn eval_A(i: uint, j: uint) -> float {
6 1.0/(((i+j)*(i+j+1u)/2u+i+1u) as float)
7 }
8
6e6798c Graydon Hoare Bulk-edit mutable -> mut.
graydon authored
9 fn eval_A_times_u(u: [const float], Au: [mut float]) {
7c8d128 Brian Anderson bench: Add shootout-spectralnorm
brson authored
10 let N = vec::len(u);
dc07280 Niko Matsakis make --enforce-mut-vars always on, add mut annotations to remaining file...
nikomatsakis authored
11 let mut i = 0u;
7c8d128 Brian Anderson bench: Add shootout-spectralnorm
brson authored
12 while i < N {
13 Au[i] = 0.0;
dc07280 Niko Matsakis make --enforce-mut-vars always on, add mut annotations to remaining file...
nikomatsakis authored
14 let mut j = 0u;
7c8d128 Brian Anderson bench: Add shootout-spectralnorm
brson authored
15 while j < N {
16 Au[i] += eval_A(i, j) * u[j];
17 j += 1u;
18 }
19 i += 1u;
20 }
21 }
22
6e6798c Graydon Hoare Bulk-edit mutable -> mut.
graydon authored
23 fn eval_At_times_u(u: [const float], Au: [mut float]) {
7c8d128 Brian Anderson bench: Add shootout-spectralnorm
brson authored
24 let N = vec::len(u);
dc07280 Niko Matsakis make --enforce-mut-vars always on, add mut annotations to remaining file...
nikomatsakis authored
25 let mut i = 0u;
7c8d128 Brian Anderson bench: Add shootout-spectralnorm
brson authored
26 while i < N {
27 Au[i] = 0.0;
dc07280 Niko Matsakis make --enforce-mut-vars always on, add mut annotations to remaining file...
nikomatsakis authored
28 let mut j = 0u;
7c8d128 Brian Anderson bench: Add shootout-spectralnorm
brson authored
29 while j < N {
30 Au[i] += eval_A(j, i) * u[j];
31 j += 1u;
32 }
33 i += 1u;
34 }
35 }
36
6e6798c Graydon Hoare Bulk-edit mutable -> mut.
graydon authored
37 fn eval_AtA_times_u(u: [const float], AtAu: [mut float]) {
cd72b1f Brian Anderson Overhaul constructor naming in libs
brson authored
38 let v = vec::to_mut(vec::from_elem(vec::len(u), 0.0));
7c8d128 Brian Anderson bench: Add shootout-spectralnorm
brson authored
39 eval_A_times_u(u, v);
40 eval_At_times_u(v, AtAu);
41 }
42
43 fn main(args: [str]) {
4fec4cd Brian Anderson bench: Add hard mode to benchmarks. Activate with RUST_BENCH.
brson authored
44 let args = if os::getenv("RUST_BENCH").is_some() {
45 ["", "2000"]
46 } else if args.len() <= 1u {
47 ["", "1000"]
7c8d128 Brian Anderson bench: Add shootout-spectralnorm
brson authored
48 } else {
4fec4cd Brian Anderson bench: Add hard mode to benchmarks. Activate with RUST_BENCH.
brson authored
49 args
7c8d128 Brian Anderson bench: Add shootout-spectralnorm
brson authored
50 };
51
4fec4cd Brian Anderson bench: Add hard mode to benchmarks. Activate with RUST_BENCH.
brson authored
52 let N = uint::from_str(args[1]).get();
53
cd72b1f Brian Anderson Overhaul constructor naming in libs
brson authored
54 let u = vec::to_mut(vec::from_elem(N, 1.0));
55 let v = vec::to_mut(vec::from_elem(N, 0.0));
dc07280 Niko Matsakis make --enforce-mut-vars always on, add mut annotations to remaining file...
nikomatsakis authored
56 let mut i = 0u;
7c8d128 Brian Anderson bench: Add shootout-spectralnorm
brson authored
57 while i < 10u {
58 eval_AtA_times_u(u, v);
59 eval_AtA_times_u(v, u);
60 i += 1u;
61 }
62
dc07280 Niko Matsakis make --enforce-mut-vars always on, add mut annotations to remaining file...
nikomatsakis authored
63 let mut vBv = 0.0;
64 let mut vv = 0.0;
65 let mut i = 0u;
7c8d128 Brian Anderson bench: Add shootout-spectralnorm
brson authored
66 while i < N {
67 vBv += u[i] * v[i];
68 vv += v[i] * v[i];
69 i += 1u;
70 }
71
6f5853f Graydon Hoare Libc/os/run/rand/io reorganization. Close #1373. Close #1638.
graydon authored
72 io::println(#fmt("%0.9f\n", float::sqrt(vBv / vv)));
7c8d128 Brian Anderson bench: Add shootout-spectralnorm
brson authored
73 }
Something went wrong with that request. Please try again.