source code
// The Computer Language Benchmarks Game
// https://salsa.debian.org/benchmarksgame-team/benchmarksgame/
//
// contributed by Jos Hirth
// based on the JavaScript version by Ian Osgood with modifications by Isaac Gouy
import 'dart:math' as math;
import 'dart:typed_data';
const int maxSmi32 = 0x3FFFFFFF;
double A(int i, int j) {
int div = ((i + j) * (i + j + 1) >> 1) + i + 1;
return 1.0 / div;
}
void Au(Float64List u, Float64List w) {
int len = u.length & maxSmi32;
for (int i = 0; i < len; ++i) {
double t = 0.0;
for (int j = 0; j < len; ++j) {
t += A(i, j) * u[j];
}
w[i] = t;
}
}
void Atu(Float64List w, Float64List v) {
int len = w.length & maxSmi32;
for (int i = 0; i < len; ++i) {
double t = 0.0;
for (int j = 0; j < len; ++j) {
t += A(j, i) * w[j];
}
v[i] = t;
}
}
void AtAu(Float64List u, Float64List v, Float64List w) {
Au(u, w);
Atu(w, v);
}
double spectralNorm(n) {
var u = new Float64List(n)..fillRange(0, n, 1.0),
v = new Float64List(n),
w = new Float64List(n),
vv = 0.0,
vBv = 0.0;
for (int i = 0; i < 10; ++i) {
AtAu(u, v, w);
AtAu(v, u, w);
}
for (int i = 0; i < n; ++i) {
vBv += u[i] * v[i];
vv += v[i] * v[i];
}
return math.sqrt(vBv / vv);
}
void main(args) {
int n = args.length > 0 ? int.parse(args[0]) : 100;
print(spectralNorm(n).toStringAsFixed(9));
}
notes, command-line, and program output
NOTES:
64-bit Ubuntu quad core
Dart VM version: 2.8.1 (stable) (Unknown timestamp) on "linux_x64"
--snapshot-kind=app-jit
Thu, 07 May 2020 03:56:36 GMT
MAKE:
/usr/bin/dartanalyzer spectralnorm.dartsnapshot-5.dartsnapshot
make: /usr/bin/dartanalyzer: Command not found
make: [/home/dunham/8000-benchmarksgame/nanobench/makefiles/u64q.programs.Makefile:448: spectralnorm.dartsnapshot-5.dartsnapshot_run] Error 127 (ignored)
/usr/bin/dart --snapshot=spectralnorm.dartsnapshot-5.snapshot --snapshot-kind=app-jit spectralnorm.dartsnapshot-5.dartsnapshot 100
1.274219991
3.48s to complete and log all make actions
COMMAND LINE:
/usr/bin/dart spectralnorm.dartsnapshot-5.snapshot 5500
PROGRAM OUTPUT:
1.274224153