[cig-commits] r11187 - cs/benchmark/cigma/trunk/src
luis at geodynamics.org
luis at geodynamics.org
Tue Feb 19 20:30:39 PST 2008
Author: luis
Date: 2008-02-19 20:30:39 -0800 (Tue, 19 Feb 2008)
New Revision: 11187
Added:
cs/benchmark/cigma/trunk/src/Timer.h
Modified:
cs/benchmark/cigma/trunk/src/CompareCmd.cpp
cs/benchmark/cigma/trunk/src/Makefile.am
Log:
Refactored timing code out of CompareCmd.cpp
Modified: cs/benchmark/cigma/trunk/src/CompareCmd.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/CompareCmd.cpp 2008-02-20 04:30:37 UTC (rev 11186)
+++ cs/benchmark/cigma/trunk/src/CompareCmd.cpp 2008-02-20 04:30:39 UTC (rev 11187)
@@ -1,6 +1,5 @@
#include <iostream>
#include <cassert>
-#include <ctime>
#include "CompareCmd.h"
#include "StringUtils.h"
@@ -14,6 +13,7 @@
#include "VtkReader.h"
#include "VtkWriter.h"
+#include "Timer.h"
#include "Misc.h"
@@ -284,14 +284,14 @@
//FE *fe;
Cell *cell = cell_a;
- time_t t_0, t_e;
- time(&t_0);
- t_e = t_0;
-
+ Timer timer;
if (verbose)
{
std::cout << std::setprecision(4);
- std::cout << "elts rate mins eta total progress\n";
+ timer.print_header(std::cout, "elts");
+ timer.start(nel);
+ timer.update(0);
+ std::cout << timer;
}
for (e = 0; e < nel; e++)
@@ -333,36 +333,18 @@
epsilon[e] = err;
L2 += err;
- //* XXX: debug info
- if (verbose && (e % output_frequency == 0))
+ // XXX: debug info
+ if (verbose && ((e+1) % output_frequency == 0))
{
- double elapsed_mins;
- double rate_per_min;
- double cells_per_sec;
- double remaining_mins;
- double total_mins;
- double progress;
-
- time(&t_e);
- elapsed_mins = (t_e - t_0) / 60.0;
- rate_per_min = elapsed_mins / (e + 1.0);
- cells_per_sec = (1.0/60.0) / rate_per_min;
- remaining_mins = (nel - e) * rate_per_min;
- total_mins = nel * rate_per_min;
- progress = 100 * elapsed_mins / total_mins;
-
- //std::cout << e << " " << std::flush;
- //std::cout << remaining_mins << " " << std::flush;
- std::cout << e << " " << cells_per_sec << " " << elapsed_mins << " " << remaining_mins << " " << total_mins << " " << progress << "%";
- std::cout << " \r" << std::flush;
-
- } // */
-
+ timer.update(e+1);
+ std::cout << timer;
+ }
}
if (verbose)
{
- std::cout << std::endl;
+ timer.update(nel);
+ std::cout << timer << std::endl;
}
L2 = sqrt(L2);
Modified: cs/benchmark/cigma/trunk/src/Makefile.am
===================================================================
--- cs/benchmark/cigma/trunk/src/Makefile.am 2008-02-20 04:30:37 UTC (rev 11186)
+++ cs/benchmark/cigma/trunk/src/Makefile.am 2008-02-20 04:30:39 UTC (rev 11187)
@@ -131,6 +131,7 @@
TextReader.h \
TextWriter.cpp \
TextWriter.h \
+ Timer.h \
Tri.cpp \
Tri.h \
VtkReader.cpp \
Added: cs/benchmark/cigma/trunk/src/Timer.h
===================================================================
--- cs/benchmark/cigma/trunk/src/Timer.h (rev 0)
+++ cs/benchmark/cigma/trunk/src/Timer.h 2008-02-20 04:30:39 UTC (rev 11187)
@@ -0,0 +1,78 @@
+#ifndef __TIMER_H__
+#define __TIMER_H__
+
+#include <iostream>
+#include <ctime>
+
+class Timer
+{
+public:
+ int total;
+ int current;
+ time_t t_0, t_n;
+ double elapsed_mins;
+ double mins_per_num;
+ double num_per_sec;
+ double remaining_mins;
+ double total_mins;
+ double progress;
+
+public:
+
+ Timer()
+ {
+ t_0 = 0;
+ total = 0;
+ current = 0;
+ }
+
+ ~Timer()
+ {
+ }
+
+public:
+
+ void print_header(std::ostream &os, const char *firstcol)
+ {
+ assert(firstcol != 0);
+ os << firstcol << " rate mins eta total progress\n";
+ }
+
+public:
+
+ void start(int total)
+ {
+ time(&t_0);
+ this->total = total;
+ }
+
+ void update(int current)
+ {
+ time(&t_n);
+ this->current = current;
+ elapsed_mins = (t_n - t_0) / 60.0;
+ mins_per_num = elapsed_mins / current;
+ num_per_sec = (1.0/60.0) / mins_per_num;
+ remaining_mins = (total - current) * mins_per_num;
+ total_mins = total * mins_per_num;
+ progress = 100 * elapsed_mins / total_mins;
+ }
+};
+
+
+std::ostream &operator<<(std::ostream &os, const Timer &T)
+{
+ os << T.current << " "
+ << T.num_per_sec << " "
+ << T.elapsed_mins << " "
+ << T.remaining_mins << " "
+ << T.total_mins << " "
+ << T.progress << "%"
+ << " "
+ " "
+ "\r"
+ << std::flush;
+}
+
+
+#endif
More information about the cig-commits
mailing list