Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #include "stdio.h"
  2. #include "stdlib.h"
  3. #include "time.h"
  4.  
  5. //stream blocks experiment
  6.  
  7.  
  8.  
  9. //block structure
  10. struct stream {
  11. void *data[10];
  12. unsigned short type[10];
  13. int len[10];
  14. //next block of data
  15. struct stream* next;
  16. };
  17.  
  18. typedef struct stream stream;
  19.  
  20. stream* allocate(int amount)
  21. {
  22. return (stream*)malloc(sizeof(stream) * amount);
  23. }
  24.  
  25.  
  26.  
  27. int main(void) {
  28. int i = 200000;
  29. clock_t start = clock(), diff;
  30. stream* root = (stream*)malloc(sizeof(stream));
  31. stream* travel = root;
  32. while(i--)
  33. {
  34. travel->data[0] = malloc(sizeof(int));
  35. travel->next = (stream*)malloc(sizeof(stream));
  36. travel = travel->next;
  37. }
  38. diff = clock() - start;
  39.  
  40. int msec = diff * 1000 / CLOCKS_PER_SEC;
  41. printf("Time taken %d seconds %d milliseconds", msec/1000, msec%1000);
  42. //25 ms for 2million array of integers
  43. printf("sizeof stream = %d", sizeof(stream));
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement