summaryrefslogtreecommitdiff
path: root/perf
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2011-09-13 09:40:35 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2011-09-13 12:30:58 +0100
commit05a73434fc5ce8157af70b4950ca9de4c6dd7a46 (patch)
tree395b7e252668eca506449b2c77e4438b6452c3f7 /perf
parent8218f5278e99a4f82113b6290500f0661402019e (diff)
perf/stats: Avoid overflow when summing time-squared
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'perf')
-rw-r--r--perf/cairo-stats.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/perf/cairo-stats.c b/perf/cairo-stats.c
index c422d6cc..1e25aef1 100644
--- a/perf/cairo-stats.c
+++ b/perf/cairo-stats.c
@@ -35,6 +35,7 @@ _cairo_stats_compute (cairo_stats_t *stats,
cairo_time_t sum, mean, delta, q1, q3, iqr;
cairo_time_t outlier_min, outlier_max;
int i, min_valid, num_valid;
+ double s;
assert (num_values > 0);
@@ -83,13 +84,11 @@ _cairo_stats_compute (cairo_stats_t *stats,
sum = _cairo_time_add (sum, values[i]);
mean = sum / num_valid;
- sum = 0;
+ /* Let's use a normalized std. deviation for easier comparison. */
+ s = 0;
for (i = min_valid; i < min_valid + num_valid; i++) {
- delta = values[i] - mean;
- sum += delta * delta;
+ double delta = (values[i] - mean) / (double)mean;
+ s += delta * delta;
}
-
- /* Let's use a std. deviation normalized to the mean for easier
- * comparison. */
- stats->std_dev = sqrt(sum / num_valid) / mean;
+ stats->std_dev = sqrt(s / num_valid);
}