#include <sys/mman.h>
#include <sys/time.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>

unsigned long GetClicks(void) {
    unsigned long now;
#ifdef NO_GETTOD
    struct tms dummy;
    now = (unsigned long) times(&dummy);
#else
    struct timeval date;
    struct timezone tz;
    gettimeofday(&date, &tz);
    now = date.tv_sec*1000000 + date.tv_usec;
#endif
    return now;
}

int main (int argc, char **argv) {
        char *src, *dest;
	unsigned long t1, t2;
        int bs=5242880;
	int i;

        src=malloc(bs);
        dest=malloc(bs);

        if (mlock(src,bs)) {
                perror("mlock");
                return(-1);
        }
        if (mlock(dest,bs)) {
                perror("mlock");
                return(-1);
        }

        printf("mlock()'s succeeded, transfering.\n");
	t1=GetClicks();
	for (i=0;i<10;i++) {
		memcpy(dest, src, bs);
	}
	t2=GetClicks();

	printf("Start: %lu\nEnd:   %lu\nTime:  %lu\n",t1, t2, t2-t1);

        munlock(src,bs);
        munlock(dest,bs);
	free(src);
	free(dest);
        return(0);
}

