Advertisement
Guest User

Untitled

a guest
Aug 29th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. #include <iostream>
  2. #include <memory>
  3. #include <chrono>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8.  
  9. class Test{
  10. private:
  11. int value;
  12. string name;
  13. double value2;
  14. public:
  15. Test(int v, string n, double v2) : value(v), name(n), value2(v2){}
  16. ~Test(){}
  17. };
  18.  
  19.  
  20. void singleAllocation(){
  21. chrono::system_clock::time_point start = chrono::system_clock::now();
  22. for(int i = 0; i < 3000; i++)
  23. shared_ptr<Test> sp(make_shared<Test>(10, "This is simple test", 2.3334));
  24.  
  25.  
  26. chrono::system_clock::time_point end = chrono::system_clock::now();
  27. cout<<"single allocation of 3000 objects took "
  28. <<chrono::duration_cast<chrono::microseconds>(end - start).count()
  29. <<"us.n";
  30. }
  31.  
  32. void doubleAllocation(){
  33. chrono::system_clock::time_point start = chrono::system_clock::now();
  34. for(int i = 0; i < 3000; i++)
  35. shared_ptr<Test> sp(new Test(10, "This is simple test", 2.3334));
  36. correlaction
  37.  
  38. chrono::system_clock::time_point end = chrono::system_clock::now();
  39. cout<<"nndouble allocation of 3000 objects took "
  40. <<chrono::duration_cast<chrono::microseconds>(end - start).count()
  41. <<"us.n";
  42.  
  43. }
  44.  
  45.  
  46. int main(){
  47. singleAllocation();
  48. doubleAllocation();
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement