-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.h
More file actions
33 lines (24 loc) · 726 Bytes
/
common.h
File metadata and controls
33 lines (24 loc) · 726 Bytes
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
#ifndef COMMON_H
#define COMMON_H
#include <time.h>
double get_wall_time() {
struct timespec time;
clock_gettime(CLOCK_MONOTONIC, &time);
return (double) time.tv_sec + (double) time.tv_nsec * 1e-9;
}
#define cnow ((double) clock() / CLOCKS_PER_SEC) // return CPU time in s
#define rnow get_wall_time() // return uptime in s
#include <unistd.h>
long get_file_size(const char *filename) {
FILE *file = fopen(filename, "rb");
if (file == NULL) {
return -1;
}
fseek(file, 0, SEEK_END);
long size = ftell(file);
fclose(file);
return size;
}
#define non_static_call(this, F, ...) (this)->F((this), ##__VA_ARGS__)
#define static_call(this, F, ...) (this)->F(##__VA_ARGS__)
#endif