4580984 [rkeene@sledge /home/rkeene/devel/memtest]$ cat -n memtest.c
 1 #include <sys/mman.h>
 2 #include <sys/time.h>
 3 #include <unistd.h>
 4 #include <stdlib.h>
 5 #include <stdio.h>
 6 
 7 unsigned long GetClicks(void) {
 8     unsigned long now;
 9 #ifdef NO_GETTOD
10     struct tms dummy;
11     now = (unsigned long) times(&dummy);
12 #else
13     struct timeval date;
14     struct timezone tz;
15     gettimeofday(&date, &tz);
16     now = date.tv_sec*1000000 + date.tv_usec;
17 #endif
18     return now;
19 }
20 
21 int main (int argc, char **argv) {
22         char *src, *dest;
23     unsigned long t1, t2;
24         int bs=5242880;
25     int i;
26 
27         src=malloc(bs);
28         dest=malloc(bs);
29 
30         if (mlock(src,bs)) {
31                 perror("mlock");
32                 return(-1);
33         }
34         if (mlock(dest,bs)) {
35                 perror("mlock");
36                 return(-1);
37         }
38 
39         printf("mlock()'s succeeded, transfering.\n");
40     t1=GetClicks();
41     for (i=0;i<10;i++) {
42         memcpy(dest, src, bs);
43     }
44     t2=GetClicks();
45 
46     printf("Start: %lu\nEnd:   %lu\nTime:  %lu\n",t1, t2, t2-t1);
47 
48         munlock(src,bs);
49         munlock(dest,bs);
50     free(src);
51     free(dest);
52         return(0);
53 }
4580985 [rkeene@sledge /home/rkeene/devel/memtest]$

Click here to go back to the directory listing.
Click here to download this file.
last modified: 2000-07-27 20:21:30