-
Notifications
You must be signed in to change notification settings - Fork 0
/
iops.c
61 lines (55 loc) · 1.77 KB
/
iops.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
#include "stdio.h"
#include <sys/time.h>
#include <stdlib.h>
#include "iops.h"
#define Export __attribute__((visibility("default")))
const char* spaces1 = " ";
const char* spaces2 = " ";
const char* spaces3 = " ";
Export
void get_iops_for_long_long(long long count, long long v1, long long v2, long long v3, long long v4) {
long long value = 0;
struct timeval t1, t2;
gettimeofday(&t1, NULL);
for (long long i = 0; i < count; i++) {
value += v1;
value -= v2;
value *= v3;
value /= v4;
}
gettimeofday(&t2, NULL);
long long cost = (t2.tv_sec * 1000 + t2.tv_usec / 1000) - (t1.tv_sec * 1000 + t1.tv_usec / 1000);
if (cost == 0) {
printf("Please give me a big enough count\n");
return;
}
float iops = (float)(4 * count / cost) * 1000;
// Use the value variable to avoid optimizing the entire loop
printf("%slong long%s%lld%s%lld%s%.2f [%d]\n", spaces1, spaces2, count, spaces2, cost, spaces2, iops, (int)value & 1);
}
Export
void get_iops_for_int(long long count, int v1, int v2, int v3, int v4) {
int value = 0;
struct timeval t1, t2;
gettimeofday(&t1, NULL);
for (int i = 0; i < count; i++) {
value += v1;
value -= v2;
value *= v3;
value /= v4;
}
gettimeofday(&t2, NULL);
long long cost = (t2.tv_sec * 1000 + t2.tv_usec / 1000) - (t1.tv_sec * 1000 + t1.tv_usec / 1000);
if (cost == 0) {
printf("Please give me a big enough count\n");
return;
}
float iops = (float)(4 * count / cost) * 1000;
// Use the value variable to avoid optimizing the entire loop
printf("%sint%s%lld%s%lld%s%.2f [%d]\n", spaces1, spaces3, count, spaces2, cost, spaces2, iops, value & 1);
}
// Must contains a start function for runing on nodejs with wasi feature
#ifdef WITHSTART
Export
void _start() {}
#endif