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