Falexom

lab6

May 10th, 2022 (edited)
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.09 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. int main()
  6. {
  7.     int i = 0;
  8.     int* ptr = 0;
  9.     clock_t start, stop;
  10.     int f = 2;
  11.     while (i < 30)
  12.     {
  13.         start = clock();
  14.  
  15.         for (int i = 0; i < 100000; i++)
  16.         {
  17.             ptr = (int*)malloc(f * sizeof(int));
  18.             free(ptr);
  19.         }
  20.  
  21.         stop = clock();
  22.  
  23.         double total_t = (double)(stop - start) / CLOCKS_PER_SEC;
  24.         printf("Allocated bytes: %d\n", f);
  25.         printf("Required time is: %f\n", total_t);
  26.         f *= 2;
  27.         i++;
  28.     }
  29.     return 0;
  30. }
  31.  
  32. #include <stdio.h>
  33. #include <stdlib.h>
  34. #include <time.h>
  35. #include <jemalloc/jemalloc.h>
  36.  
  37. int main()
  38. {
  39.     int i = 0;
  40.     int* ptr = 0;
  41.     clock_t start, stop;
  42.     int f = 2;
  43.     while (i < 30)
  44.     {
  45.         start = clock();
  46.  
  47.         for (int i = 0; i < 100000; i++)
  48.         {
  49.             ptr = (int*)calloc(f, sizeof(int));
  50.             free(ptr);
  51.         }
  52.  
  53.         stop = clock();
  54.  
  55.         double total_t = (double)(stop - start) / CLOCKS_PER_SEC;
  56.         printf("Allocated bytes: %d\n", f);
  57.         printf("Required time is: %f\n", total_t);
  58.         f *= 2;
  59.         i++;
  60.     }
  61.     return 0;
  62. }
Add Comment
Please, Sign In to add comment