Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [zenom@lynx c]$ cat overcommit.c
- #include <stdio.h>
- #include <stdint.h>
- #include <stdlib.h>
- #include <assert.h>
- #include <time.h>
- #define NKEYS 9000000
- int main(int argc, char** argv) {
- int i;
- clock_t start, end;
- uint32_t* collection = calloc(UINT32_MAX, sizeof(uint32_t));
- printf("Put %d uint32_t values...", NKEYS);
- start = clock();
- for (i = 0; i < NKEYS; i++)
- collection[i] = 42;
- end = clock();
- printf("took %.5f seconds\n", (end - start) / (double) CLOCKS_PER_SEC);
- printf("Retrieve %d uint32_t values...", NKEYS);
- start = clock();
- for (i = 0; i < NKEYS; i++)
- assert(collection[i] = 42);
- end = clock();
- printf("took %.5f secondds\n", (end - start) / (double) CLOCKS_PER_SEC);
- }
- [zenom@lynx c]$ sudo sysctl vm.overcommit_memory=1
- [sudo] пароль для zenom:
- vm.overcommit_memory = 1
- [zenom@lynx c]$ gcc overcommit.c
- [zenom@lynx c]$ ./a.out
- Put 9000000 uint32_t values...took 0.13819 seconds
- Retrieve 9000000 uint32_t values...took 0.02524 secondds
- [zenom@lynx c]$
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement