forked from dfelinto/opengl-sandbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.h
93 lines (75 loc) · 2.9 KB
/
utils.h
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
84
85
86
87
88
89
90
91
92
93
#ifndef __UTILS__
#define __UTILS__
#include <unistd.h>
#include <sys/time.h>
#include <iostream>
#include <fstream>
#include <cstdlib>
double PIL_check_seconds_timer(void)
{
struct timeval tv;
struct timezone tz;
gettimeofday(&tv, &tz);
return ((double) tv.tv_sec + tv.tv_usec / 1000000.0);
}
long int PIL_check_seconds_timer_i(void)
{
struct timeval tv;
struct timezone tz;
gettimeofday(&tv, &tz);
return tv.tv_sec;
}
void PIL_sleep_ms(int ms)
{
if (ms >= 1000) {
sleep(ms / 1000);
ms = (ms % 1000);
}
usleep(ms * 1000);
}
static int time_identation = 0;
#define STRINGIFY_APPEND(a, b) "" a #b
#define STRINGIFY(x) STRINGIFY_APPEND("", x)
#define AT __FILE__ ":" STRINGIFY(__LINE__)
#define TIME_TAB \
for (int _i = 0; _i < time_identation; _i++) { \
printf("\t"); \
}
#define TIMEIT_START(var) \
{ \
time_identation ++; \
TIME_TAB \
double _timeit_##var = PIL_check_seconds_timer(); \
printf("time start \t " AT "\t(" #var "): \t%5s--\n", "-"); \
fflush(stdout); \
{ (void)0
/**
* \return the time since TIMEIT_START was called.
*/
#define TIMEIT_VALUE(var) (float)(PIL_check_seconds_timer() - _timeit_##var) * 1000.0f
#define TIMEIT_VALUE_PRINT(var) \
{ \
TIME_TAB \
printf("time update \t " AT "\t(" #var "): \t%5.fms\n", TIMEIT_VALUE(var)); \
fflush(stdout); \
} (void)0
#define TIMEIT_END(var) \
} \
TIME_TAB \
printf("time end \t " AT "\t(" #var "): \t%5.fms\n", TIMEIT_VALUE(var)); \
fflush(stdout); \
time_identation--; \
} (void)0
bool readFileIntoString( const std::string &fileName, std::string &destination ) {
std::ifstream in( fileName, std::ios::in | std::ios::binary );
if ( in ) {
in.seekg( 0, std::ios::end );
destination.resize( in.tellg() );
in.seekg( 0, std::ios::beg );
in.read( &destination[ 0 ], destination.size() );
in.close();
return true;
}
return false;
}
#endif /* __UTILS__ */