forked from jzplp/OSTEP-Answers
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path19.7.c
More file actions
30 lines (27 loc) · 615 Bytes
/
Copy path19.7.c
File metadata and controls
30 lines (27 loc) · 615 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
#include<stdio.h>
#include<sys/time.h>
#include<stdlib.h>
#define PAGESIZE 4096
int main(int argc, char *argv[])
{
if(argc != 3) {
fprintf(stderr, "error parameters!");
exit(0);
}
struct timeval start, end;
int pageNum = atoi(argv[1]);
int i,j, num = atoi(argv[2]);
char arr[PAGESIZE * pageNum];
for(i=0; i<PAGESIZE*pageNum; ++i) {
arr[i] = 0;
}
gettimeofday(&start, NULL);
for(j=0; j<num; ++j) {
for(i=0; i<pageNum; ++i) {
arr[i*4096]=1;
}
}
gettimeofday(&end, NULL);
printf("%lf %d %d\n", (((double)end.tv_usec - start.tv_usec)/pageNum)/num, end.tv_usec, start.tv_usec);
return 0;
}