-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtlb.c
More file actions
38 lines (30 loc) · 641 Bytes
/
tlb.c
File metadata and controls
38 lines (30 loc) · 641 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
34
35
36
37
38
/*
demonstrate the TLB misses by parsing a large array
*/
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main (void)
{
const unsigned long long size = 100000999LLU;
long long *data;
data = (long long *) calloc (size, sizeof (long long));
if (NULL == data)
{
fprintf (stderr, "cannot allocate memory\n");
return 1;
}
time_t start, stop;
double diff = 0;
time (&start);
int i;
for (i = 0; i != size; ++i)
{
data[i] = i * 4;
}
time (&stop);
diff = difftime (stop, start);
printf ("it took %.2lf seconds to parse the array\n", diff);
free (data);
return 0;
}