Guest User

Untitled

a guest
Sep 29th, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. // randomFreeRandomMalloc.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <stdio.h>
  6. #include <vector>
  7. #include <queue>
  8. #include <chrono>
  9. #include <iostream>
  10. using namespace std;
  11. static size_t timestamp()
  12. {
  13. return chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count();
  14. }
  15. int main()
  16. {
  17. const int times = 100;
  18. const size_t bytes = 1048576*10;//10 megabytes
  19. auto start = timestamp();
  20. //
  21. queue<unsigned char*> fillMe;
  22. for (int i = 0 ; i < times; i++)
  23. {
  24. auto a = (unsigned char*) malloc(bytes);
  25. fillMe.push(a);
  26. }
  27. for (int i = 0 ; i < times; i++)
  28. {
  29. auto a = fillMe.front();
  30. fillMe.pop();
  31. free(a);
  32. }
  33. auto stop = timestamp();
  34. cout << (stop - start)/(times*1.0f) << endl;
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment