Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/stat.h>
- #include <math.h>
- #include <fcntl.h>
- #include <sys/time.h>
- #include <sys/types.h>
- #include <sys/mman.h>
- #include <unistd.h>
- #include <string.h>
- int main(int argc, char *argv[])
- {
- struct timeval tv;
- gettimeofday(&tv, NULL);
- int start = tv.tv_usec;
- struct stat st;
- stat(argv[1], &st);
- int size = st.st_size;
- printf("File size: %d\n", size);
- int half = round(size/2);
- int half2 = size - half;
- int f = open(argv[1], O_RDONLY);
- int f2 = open(argv[2], O_RDWR | O_CREAT, 0664);
- void *src, *dst;
- lseek(f2, size-1, SEEK_SET);
- write(f2, "", 1);
- src = mmap(NULL, size, PROT_READ, MAP_SHARED, f, 0);
- dst = mmap(NULL, size, PROT_WRITE, MAP_SHARED, f2, 0);
- memcpy(dst, (void*)(src + half), half);
- memcpy((void*)(dst + half), src, half2);
- gettimeofday(&tv, NULL);
- int end = tv.tv_usec;
- double time = end - start;
- printf("Done in %f seconds\n", time/1000000);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement