From: Tim King Date: Wed, 3 Nov 2010 01:07:09 +0000 (+0000) Subject: Adds AverageStat to stats.h. X-Git-Tag: cvc5-1.0.0~8752 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a7f99ba2844707d1b405e1cd3c01404c9e43850a;p=cvc5.git Adds AverageStat to stats.h. --- diff --git a/src/util/stats.h b/src/util/stats.h index d6b463e65..02b642939 100644 --- a/src/util/stats.h +++ b/src/util/stats.h @@ -263,6 +263,32 @@ public: };/* class IntStat */ +/** + * The value for an AverageStat is the running average of (e1, e_2, ..., e_n), + * (e1 + e_2 + ... + e_n)/n, + * where e_i is an entry added by an addEntry(e_i) call. + * The value is initially always 0. + * (This is to avoid making parsers confused.) + */ +class AverageStat : public BackedStat { +private: + uint32_t n; + +public: + AverageStat(const std::string& s) : + BackedStat(s, 0.0 ), n(0) { + } + + void addEntry(double e){ + double oldSum = n*getData(); + ++n; + double newSum = oldSum + e; + setData(newSum / n); + } + +};/* class AverageStat */ + + // some utility functions for ::timespec inline ::timespec& operator+=(::timespec& a, const ::timespec& b) { // assumes a.tv_nsec and b.tv_nsec are in range