aboutsummaryrefslogtreecommitdiff
path: root/samples/OpenGL/compute_shader/stats.c
diff options
context:
space:
mode:
authorWolfgang Draxinger <Wolfgang.Draxinger@draxit.de>2016-04-24 23:33:05 +0200
committerWolfgang Draxinger <Wolfgang.Draxinger@draxit.de>2016-04-24 23:33:05 +0200
commita00fb682a7e3552ab4f5ee0a161d0e21d17d6a26 (patch)
tree4c25244223bde246c97cce0335da0dad4e353959 /samples/OpenGL/compute_shader/stats.c
parent1e387fc8eee4925616967edd26de0ee416dbce3f (diff)
downloadcodesamples-a00fb682a7e3552ab4f5ee0a161d0e21d17d6a26.tar.gz
codesamples-a00fb682a7e3552ab4f5ee0a161d0e21d17d6a26.tar.bz2
computeshader
Diffstat (limited to 'samples/OpenGL/compute_shader/stats.c')
-rw-r--r--samples/OpenGL/compute_shader/stats.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/samples/OpenGL/compute_shader/stats.c b/samples/OpenGL/compute_shader/stats.c
new file mode 100644
index 0000000..1cf7fcb
--- /dev/null
+++ b/samples/OpenGL/compute_shader/stats.c
@@ -0,0 +1,25 @@
+#include "stats.h"
+
+void stats_running_reset(struct stats_running *s)
+{
+ if( s ) {
+ s->n = 0;
+ s->S = NAN;
+ s->m = NAN;
+ }
+}
+
+void stats_running_push(struct stats_running *s, double value)
+{
+ if( s && isfinite(value) ) {
+ double const m_prev = 0 < s->n ? s->m : 0.;
+ double const S_prev = 1 < s->n ? s->S : 0.;
+ unsigned const n = (s->n += 1);
+
+ s->m = m_prev + (value - m_prev) / n;
+ if( 1 < n ) {
+ /* variance is defined only for n > 1 */
+ s->S = S_prev + (value - s->m) * (value - m_prev);
+ }
+ }
+}