summaryrefslogtreecommitdiff
path: root/tests/variable.c
diff options
context:
space:
mode:
authorOwen W. Taylor <otaylor@fishsoup.net>2012-11-14 17:54:03 -0500
committerOwen W. Taylor <otaylor@fishsoup.net>2013-02-14 17:19:51 -0500
commit9690567d5059e5667803e5b8fb438c3b97e9d7e7 (patch)
tree82fc80b2f692e74085ab79497a8a3a7981f43bd8 /tests/variable.c
parent574301d34d6e2f08f05942e0d4ec20b40b686ee1 (diff)
downloadgtk+-9690567d5059e5667803e5b8fb438c3b97e9d7e7.tar.gz
animated-resizing: enhance output
Show the average and standard deviation of the latency in addition to the frame rate. Add options to print the output in machine-readable form, and to control the frequency and total number of statistics that will be output. https://bugzilla.gnome.org/show_bug.cgi?id=685460
Diffstat (limited to 'tests/variable.c')
-rw-r--r--tests/variable.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/variable.c b/tests/variable.c
new file mode 100644
index 0000000000..9ce5d5d6ab
--- /dev/null
+++ b/tests/variable.c
@@ -0,0 +1,43 @@
+/* -*- mode: C; c-basic-offset: 2; indent-tabs-mode: nil; -*- */
+
+#include <math.h>
+#include "variable.h"
+
+void
+variable_add_weighted (Variable *variable,
+ double value,
+ double weight)
+{
+ variable->weight += weight;
+ variable->sum += weight * value;
+ variable->sum2 += weight * value * value;
+}
+
+void
+variable_add (Variable *variable,
+ double value)
+{
+ variable_add_weighted (variable, value, 1.);
+}
+
+double
+variable_mean (Variable *variable)
+{
+ return variable->sum / variable->weight;
+}
+
+double
+variable_standard_deviation (Variable *variable)
+{
+ double mean = variable_mean (variable);
+ return sqrt (variable->sum2 / variable->weight - mean * mean);
+}
+
+void
+variable_reset (Variable *variable)
+{
+ variable->weight = 0;
+ variable->sum = 0;
+ variable->sum2 = 0;
+}
+