From 8724cf43c27922c2a9eb10846bafbe2f3d8f7cef Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sun, 29 Sep 2019 19:08:30 -0400 Subject: nserver: Add stats.h --- nserver/src/stats.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 nserver/src/stats.h (limited to 'nserver/src/stats.h') diff --git a/nserver/src/stats.h b/nserver/src/stats.h new file mode 100644 index 0000000..997a505 --- /dev/null +++ b/nserver/src/stats.h @@ -0,0 +1,33 @@ +#ifndef stats_h +#define stats_h +#include + +typedef struct Stats { + double sum; + double sumsq; + unsigned long n; + double min; + double max; +} Stats; + +Stats *Stats_recreate(double sum, double sumsq, unsigned long n, + double min, double max); + +Stats *Stats_create(); + +void Stats_sample(Stats *st, double s); + +void Stats_dump(Stats *st); + +static inline double Stats_mean(Stats *st) +{ + return st->sum / st->n; +} + +static inline double Stats_stddev(Stats *st) +{ + return sqrt((st->sumsq - (st->sum * st->sum / st->n)) / + (st->n - 1)); +} + +#endif -- cgit v1.2.3