Guest User

Untitled

a guest
Oct 16th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. diff --git i/Makefile w/Makefile
  2. --- i/Makefile
  3. +++ w/Makefile
  4. @@ -492,8 +493,10 @@ TEST_PROGRAMS_NEED_X += test-line-buffer
  5. TEST_PROGRAMS_NEED_X += test-match-trees
  6. TEST_PROGRAMS_NEED_X += test-mergesort
  7. TEST_PROGRAMS_NEED_X += test-mktemp
  8. +TEST_PROGRAMS_NEED_X += test-mmap
  9. TEST_PROGRAMS_NEED_X += test-parse-options
  10. TEST_PROGRAMS_NEED_X += test-path-utils
  11. +TEST_PROGRAMS_NEED_X += test-pread
  12. TEST_PROGRAMS_NEED_X += test-revision-walking
  13. TEST_PROGRAMS_NEED_X += test-run-command
  14. TEST_PROGRAMS_NEED_X += test-scrap-cache-tree
  15. diff --git i/test-mmap.c w/test-mmap.c
  16. index e69de29..c9a42ee 100644
  17. --- i/test-mmap.c
  18. +++ w/test-mmap.c
  19. @@ -0,0 +1,46 @@
  20. +#include "git-compat-util.h"
  21. +#include <zlib.h>
  22. +#include <sys/types.h>
  23. +#include <sys/stat.h>
  24. +#include <fcntl.h>
  25. +#include <unistd.h>
  26. +#include <sys/mman.h>
  27. +
  28. +int rep = 100;
  29. +
  30. +int main (int argc, char *argv[])
  31. +
  32. +{
  33. + struct stat st;
  34. + int fd;
  35. + void *map;
  36. + unsigned int accum = 0;
  37. + int pcount;
  38. +
  39. + if (argc != 2)
  40. + die("usage: %s <file>\n", argv[0]);
  41. + fd = open(argv[1], O_RDONLY);
  42. + if (fd < 0)
  43. + die_errno("open");
  44. + if (fstat(fd, &st) < 0)
  45. + die_errno("fstat");
  46. +
  47. + pcount = st.st_size / 4096;
  48. +
  49. + while (rep--) {
  50. + int i;
  51. + map = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
  52. + if (map == MAP_FAILED)
  53. + die_errno("mmap");
  54. +
  55. + for (i = 0; i < pcount; i++) {
  56. + int *p = (int*) (map + 4096*i);
  57. + accum += *p;
  58. + }
  59. +
  60. + munmap(map, st.st_size);
  61. + }
  62. + printf("%8x\n", accum);
  63. +
  64. + return 0;
  65. +}
  66. diff --git i/test-pread.c w/test-pread.c
  67. index e69de29..964b115 100644
  68. --- i/test-pread.c
  69. +++ w/test-pread.c
  70. @@ -0,0 +1,43 @@
  71. +#include "git-compat-util.h"
  72. +#include <zlib.h>
  73. +#include <sys/types.h>
  74. +#include <sys/stat.h>
  75. +#include <fcntl.h>
  76. +#include <unistd.h>
  77. +#include <sys/mman.h>
  78. +
  79. +int rep = 100;
  80. +
  81. +int main (int argc, char *argv[])
  82. +
  83. +{
  84. + struct stat st;
  85. + int fd;
  86. + unsigned int accum = 0;
  87. + int pcount;
  88. +
  89. + if (argc != 2)
  90. + die("usage: %s <file>\n", argv[0]);
  91. + fd = open(argv[1], O_RDONLY);
  92. + if (fd < 0)
  93. + die_errno("open");
  94. + if (fstat(fd, &st) < 0)
  95. + die_errno("fstat");
  96. +
  97. + pcount = st.st_size / 4096;
  98. +
  99. + while (rep--) {
  100. + int i;
  101. + char buf[4096];
  102. + int *p = (int*) buf;
  103. +
  104. + for (i = 0; i < pcount; i++) {
  105. + if (pread(fd, buf, 4, i*4096) < 0)
  106. + die_errno("pread");
  107. + accum += *p;
  108. + }
  109. + }
  110. + printf("%8x\n", accum);
  111. +
  112. + return 0;
  113. +}
Add Comment
Please, Sign In to add comment