Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git i/Makefile w/Makefile
- --- i/Makefile
- +++ w/Makefile
- @@ -492,8 +493,10 @@ TEST_PROGRAMS_NEED_X += test-line-buffer
- TEST_PROGRAMS_NEED_X += test-match-trees
- TEST_PROGRAMS_NEED_X += test-mergesort
- TEST_PROGRAMS_NEED_X += test-mktemp
- +TEST_PROGRAMS_NEED_X += test-mmap
- TEST_PROGRAMS_NEED_X += test-parse-options
- TEST_PROGRAMS_NEED_X += test-path-utils
- +TEST_PROGRAMS_NEED_X += test-pread
- TEST_PROGRAMS_NEED_X += test-revision-walking
- TEST_PROGRAMS_NEED_X += test-run-command
- TEST_PROGRAMS_NEED_X += test-scrap-cache-tree
- diff --git i/test-mmap.c w/test-mmap.c
- index e69de29..c9a42ee 100644
- --- i/test-mmap.c
- +++ w/test-mmap.c
- @@ -0,0 +1,46 @@
- +#include "git-compat-util.h"
- +#include <zlib.h>
- +#include <sys/types.h>
- +#include <sys/stat.h>
- +#include <fcntl.h>
- +#include <unistd.h>
- +#include <sys/mman.h>
- +
- +int rep = 100;
- +
- +int main (int argc, char *argv[])
- +
- +{
- + struct stat st;
- + int fd;
- + void *map;
- + unsigned int accum = 0;
- + int pcount;
- +
- + if (argc != 2)
- + die("usage: %s <file>\n", argv[0]);
- + fd = open(argv[1], O_RDONLY);
- + if (fd < 0)
- + die_errno("open");
- + if (fstat(fd, &st) < 0)
- + die_errno("fstat");
- +
- + pcount = st.st_size / 4096;
- +
- + while (rep--) {
- + int i;
- + map = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
- + if (map == MAP_FAILED)
- + die_errno("mmap");
- +
- + for (i = 0; i < pcount; i++) {
- + int *p = (int*) (map + 4096*i);
- + accum += *p;
- + }
- +
- + munmap(map, st.st_size);
- + }
- + printf("%8x\n", accum);
- +
- + return 0;
- +}
- diff --git i/test-pread.c w/test-pread.c
- index e69de29..964b115 100644
- --- i/test-pread.c
- +++ w/test-pread.c
- @@ -0,0 +1,43 @@
- +#include "git-compat-util.h"
- +#include <zlib.h>
- +#include <sys/types.h>
- +#include <sys/stat.h>
- +#include <fcntl.h>
- +#include <unistd.h>
- +#include <sys/mman.h>
- +
- +int rep = 100;
- +
- +int main (int argc, char *argv[])
- +
- +{
- + struct stat st;
- + int fd;
- + unsigned int accum = 0;
- + int pcount;
- +
- + if (argc != 2)
- + die("usage: %s <file>\n", argv[0]);
- + fd = open(argv[1], O_RDONLY);
- + if (fd < 0)
- + die_errno("open");
- + if (fstat(fd, &st) < 0)
- + die_errno("fstat");
- +
- + pcount = st.st_size / 4096;
- +
- + while (rep--) {
- + int i;
- + char buf[4096];
- + int *p = (int*) buf;
- +
- + for (i = 0; i < pcount; i++) {
- + if (pread(fd, buf, 4, i*4096) < 0)
- + die_errno("pread");
- + accum += *p;
- + }
- + }
- + printf("%8x\n", accum);
- +
- + return 0;
- +}
Add Comment
Please, Sign In to add comment