-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.h
47 lines (37 loc) · 1.17 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
/*
* Copyright (C) 2011 Universidad Simon Bolivar
*
* Permission is hereby granted to distribute this software for
* non-commercial research purposes, provided that this copyright
* notice is included with any such distribution.
*
* THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
* EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
* SOFTWARE IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU
* ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
*
* Blai Bonet, bonet@ldc.usb.ve
*
*/
#ifndef UTILS_H
#define UTILS_H
#include <cassert>
#include <iostream>
#include <sys/resource.h>
#include <sys/time.h>
//#define DEBUG
namespace Utils {
inline float read_time_in_seconds() {
struct rusage r_usage;
getrusage(RUSAGE_SELF, &r_usage);
return (float)r_usage.ru_utime.tv_sec +
(float)r_usage.ru_utime.tv_usec / (float)1000000;
}
template<typename T> inline T abs(const T a) {
return a < 0 ? -a : a;
}
} // end of namespace
#undef DEBUG
#endif