OLD | NEW |
| (Empty) |
1 part of dromaeo; | |
2 | |
3 class Result { | |
4 int get runs { return _sorted.length; } | |
5 | |
6 double get sum { | |
7 double result = 0.0; | |
8 _sorted.forEach((double e) { result += e; }); | |
9 return result; | |
10 } | |
11 | |
12 double get min { return _sorted[0]; } | |
13 double get max { return _sorted[runs - 1]; } | |
14 | |
15 double get mean { return sum / runs; } | |
16 | |
17 double get median { | |
18 return (runs % 2 == 0) ? | |
19 (_sorted[runs ~/ 2] + _sorted[runs ~/ 2 + 1]) / 2 : _sorted[runs ~/ 2]; | |
20 } | |
21 | |
22 double get variance { | |
23 double m = mean; | |
24 double result = 0.0; | |
25 _sorted.forEach((double e) { result += Math.pow(e - m, 2.0); }); | |
26 return result / (runs - 1); | |
27 } | |
28 | |
29 double get deviation { return Math.sqrt(variance); } | |
30 | |
31 // Compute Standard Errors Mean | |
32 double get sem { return (deviation / Math.sqrt(runs)) * T_DISTRIBUTION; } | |
33 | |
34 double get error { return (sem / mean) * 100; } | |
35 | |
36 // TODO: Implement writeOn. | |
37 String toString() { | |
38 return '[Result: mean = ${mean}]'; | |
39 } | |
40 | |
41 factory Result(List<double> runsPerSecond) { | |
42 runsPerSecond.sort((a, b) => a.compareTo(b)); | |
43 return new Result._internal(runsPerSecond); | |
44 } | |
45 | |
46 Result._internal(this._sorted) {} | |
47 | |
48 List<double> _sorted; | |
49 | |
50 // Populated from: http://www.medcalc.be/manual/t-distribution.php | |
51 // 95% confidence for N - 1 = 4 | |
52 static const double T_DISTRIBUTION = 2.776; | |
53 } | |
OLD | NEW |