aboutsummaryrefslogtreecommitdiff
path: root/Carpet/CarpetLib
diff options
context:
space:
mode:
authorErik Schnetter <schnetter@cct.lsu.edu>2006-09-25 21:48:00 +0000
committerErik Schnetter <schnetter@cct.lsu.edu>2006-09-25 21:48:00 +0000
commit419867d169431cfa83fb11ca646e45f08e6e6244 (patch)
tree76a03d9971d2a05e2505078feeedd943c087f3dc /Carpet/CarpetLib
parentef689afe532450a41688ead23b3b53e7f7a68a9a (diff)
CarpetLib: Avoid nans in timer output
Avoid nans in timer output; instead of dividing by zero, set the result to zero. darcs-hash:20060925214858-dae7b-0c82bb1a3dc1a3080955b86324487e4a7efc044e.gz
Diffstat (limited to 'Carpet/CarpetLib')
-rw-r--r--Carpet/CarpetLib/src/timestat.cc16
1 files changed, 12 insertions, 4 deletions
diff --git a/Carpet/CarpetLib/src/timestat.cc b/Carpet/CarpetLib/src/timestat.cc
index 5e8b0b599..b126471be 100644
--- a/Carpet/CarpetLib/src/timestat.cc
+++ b/Carpet/CarpetLib/src/timestat.cc
@@ -63,10 +63,18 @@ void timestat::stop (double const b)
ostream& operator<< (ostream& os, const timestat& wt)
{
- double const avg = wt.wtime / wt.count;
- double const stddev = sqrt (max (0.0, wt.wtime2 / wt.count - pow (avg, 2)));
- double const bavg = wt.bytes / wt.count;
- double const bstddev = sqrt (max (0.0, wt.bytes2 / wt.count - pow (bavg, 2)));
+ double avg, stddev, bavg, bstddev;
+ if (wt.count == 0.0) {
+ avg = 0.0;
+ stddev = 0.0;
+ bavg = 0.0;
+ bstddev = 0.0;
+ } else {
+ avg = wt.wtime / wt.count;
+ stddev = sqrt (max (0.0, wt.wtime2 / wt.count - pow (avg, 2)));
+ bavg = wt.bytes / wt.count;
+ bstddev = sqrt (max (0.0, wt.bytes2 / wt.count - pow (bavg, 2)));
+ }
os << "timestat[seconds]:"
<< " cnt: " << wt.count
<< " time: sum: " << wt.wtime