Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2016
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. [zenom@lynx c]$ cat overcommit.c
  2. #include <stdio.h>
  3. #include <stdint.h>
  4. #include <stdlib.h>
  5. #include <assert.h>
  6. #include <time.h>
  7.  
  8. #define NKEYS 9000000
  9.  
  10. int main(int argc, char** argv) {
  11. int i;
  12. clock_t start, end;
  13. uint32_t* collection = calloc(UINT32_MAX, sizeof(uint32_t));
  14.  
  15. printf("Put %d uint32_t values...", NKEYS);
  16. start = clock();
  17.  
  18. for (i = 0; i < NKEYS; i++)
  19. collection[i] = 42;
  20. end = clock();
  21. printf("took %.5f seconds\n", (end - start) / (double) CLOCKS_PER_SEC);
  22.  
  23. printf("Retrieve %d uint32_t values...", NKEYS);
  24. start = clock();
  25.  
  26. for (i = 0; i < NKEYS; i++)
  27. assert(collection[i] = 42);
  28. end = clock();
  29. printf("took %.5f secondds\n", (end - start) / (double) CLOCKS_PER_SEC);
  30. }
  31.  
  32. [zenom@lynx c]$ sudo sysctl vm.overcommit_memory=1
  33. [sudo] пароль для zenom:
  34. vm.overcommit_memory = 1
  35.  
  36. [zenom@lynx c]$ gcc overcommit.c
  37.  
  38. [zenom@lynx c]$ ./a.out
  39. Put 9000000 uint32_t values...took 0.13819 seconds
  40. Retrieve 9000000 uint32_t values...took 0.02524 secondds
  41. [zenom@lynx c]$
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement