[go: up one dir, main page]

Menu

[9bd658]: / src / Common / amp.cc  Maximize  Restore  History

Download this file

85 lines (68 with data), 1.4 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "amp.hh"
#include <new>
#include <cstdio>
#include <iostream>
#include <cstring>
#include <ctime>
using namespace std;
#define MAX_FILE_NAME 1024
const char * Date
( )
// Returns a date and time string
{
int last;
char * cp;
time_t tp;
time (&tp);
cp = asctime (localtime (&tp));
last = strlen(cp) - 1;
if ( cp [last] == '\n' )
cp [last] = '\0';
return cp;
}
void ProgressDots_t::update (long long progress)
{
int dots = (long long)((double)progress / (double)end_m * (double)count_m);
while ( total_m < dots && total_m < count_m )
{
cerr << '.';
total_m ++;
}
}
void ProgressDots_t::end ( )
{
update (end_m);
cerr << endl;
}
EventTime_t::EventTime_t()
{
start();
memset(&m_end, 0, sizeof(struct timeval));
}
void EventTime_t::start()
{
gettimeofday(&m_start, NULL);
}
void EventTime_t::end()
{
gettimeofday(&m_end, NULL);
}
double EventTime_t::length()
{
if ((m_end.tv_sec == 0) && (m_end.tv_usec == 0)) { end(); }
return ((m_end.tv_sec - m_start.tv_sec)*1000000.0 + (m_end.tv_usec - m_start.tv_usec)) / 1e6;
}
string EventTime_t::str(bool format, int precision)
{
double r = length();
char buffer[1024];
sprintf(buffer, "%0.*f", precision, r);
if (format)
{
string s("[");
s += buffer;
s += "s]";
return s;
}
return buffer;
}