-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.c
70 lines (48 loc) · 1.28 KB
/
util.c
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
#include <sys/types.h>
#include <sys/stat.h>
#include <pthread.h>
#include <sys/time.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <linux/aio_abi.h>
#include <fcntl.h>
#include <string.h>
#include <inttypes.h>
#include <sched.h>
#include <signal.h>
#include <time.h>
#include "util.h"
double time_diff(struct timeval x , struct timeval y)
{
double x_ms , y_ms , diff;
x_ms = (double)x.tv_sec*1000000 + (double)x.tv_usec;
y_ms = (double)y.tv_sec*1000000 + (double)y.tv_usec;
diff = (double)y_ms - (double)x_ms;
return diff;
}
double time_per_tick(int n, int del) {
int i;
double *td = (double*)malloc(n * sizeof(double));
double *tv = (double*)malloc(n * sizeof(double));
struct timeval tvs;
struct timeval tve;
uint64_t ts;
uint64_t te;
for (i=0; i<n; i++) {
gettimeofday(&tvs, NULL);
ts = getticks();
usleep(del);
te = getticks();
gettimeofday(&tve, NULL);
td[i] = elapsed(te,ts);
tv[i] = time_diff(tvs,tve);
}
double sum = 0.0;
for(i=0; i<n; i++) {
sum += 1000.0 * tv[i] / td[i];
//printf("ticks, %15g, time, %15g, ticks/usec, %15g, nsec/tick, %15g\n", td[i], tv[i], td[i] / tv[i], 1000.0 * tv[i] / td[i]);
}
return sum / n ;
}