-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcache_test.c
47 lines (40 loc) · 1010 Bytes
/
cache_test.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
#define _GNU_SOURCE
#include<stdio.h>
#include<fcntl.h>
#include<time.h>
#include<string.h>
#include<malloc.h>
#include<stdlib.h>
#include<sys/mman.h>
#include<sys/time.h>
int main(int argc, char **argv)
{
int fd, i;
long long time, time1;
unsigned long long FILE_SIZE;
size_t len;
off_t offset;
char unit;
struct timespec start, end;
struct timespec begin, finish;
struct timezone tz;
int size;
unsigned long long count;
char *buf, *data;
clock_gettime(CLOCK_MONOTONIC, &begin);
for (i = 0; i < 1; i++) {
getuid();
}
clock_gettime(CLOCK_MONOTONIC, &finish);
buf = malloc(4096);
memset(buf, 'c', 4096);
fd = open("/mnt/ramdisk/test2", O_RDWR | O_CREAT, 0640);
data = (char *)mmap(NULL, 4096, PROT_WRITE, MAP_SHARED, fd, 0);
// write(fd, buf, 4096);
// memcpy(data, buf, 4096);
munmap(data, 4096);
close(fd);
time1 = (finish.tv_sec * 1e9 + finish.tv_nsec) - (begin.tv_sec * 1e9 + begin.tv_nsec);
printf("getuid %lld ns, average %lld ns\n", time1, time1 / 1000000);
return 0;
}