update scripts
[c11concurrency-benchmarks.git] / silo / masstree / kvstats.hh
1 /* Masstree
2  * Eddie Kohler, Yandong Mao, Robert Morris
3  * Copyright (c) 2012-2013 President and Fellows of Harvard College
4  * Copyright (c) 2012-2013 Massachusetts Institute of Technology
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, subject to the conditions
9  * listed in the Masstree LICENSE file. These conditions include: you must
10  * preserve this copyright notice, and you cannot mention the copyright
11  * holders in advertising related to the Software without their permission.
12  * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This
13  * notice is a summary of the Masstree LICENSE file; the license in that file
14  * is legally binding.
15  */
16 #ifndef KVSTATS_HH
17 #define KVSTATS_HH 1
18 #include <stdlib.h>
19
20 struct kvstats {
21   double min, max, sum, sumsq;
22   long count;
23   kvstats()
24     : min(-1), max(-1), sum(0), sumsq(0), count(0) {
25   }
26   void add(double x) {
27     if (!count || x < min)
28       min = x;
29     if (max < x)
30       max = x;
31     sum += x;
32     sumsq += x * x;
33     count += 1;
34   }
35   typedef void (kvstats::*unspecified_bool_type)(double);
36   operator unspecified_bool_type() const {
37     return count ? &kvstats::add : 0;
38   }
39   void print_report(const char *name) const {
40     if (count)
41       printf("%s: n %ld, total %.0f, average %.0f, min %.0f, max %.0f, stddev %.0f\n",
42              name, count, sum, sum / count, min, max,
43              sqrt((sumsq - sum * sum / count) / (count - 1)));
44   }
45   double avg() {
46     if (count)
47       return sum / count;
48     else
49       return 0;
50   }
51 };
52
53 #endif