Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <memory>
- #include <chrono>
- #include <string>
- using namespace std;
- class Test{
- private:
- int value;
- string name;
- double value2;
- public:
- Test(int v, string n, double v2) : value(v), name(n), value2(v2){}
- ~Test(){}
- };
- void singleAllocation(){
- chrono::system_clock::time_point start = chrono::system_clock::now();
- for(int i = 0; i < 3000; i++)
- shared_ptr<Test> sp(make_shared<Test>(10, "This is simple test", 2.3334));
- chrono::system_clock::time_point end = chrono::system_clock::now();
- cout<<"single allocation of 3000 objects took "
- <<chrono::duration_cast<chrono::microseconds>(end - start).count()
- <<"us.n";
- }
- void doubleAllocation(){
- chrono::system_clock::time_point start = chrono::system_clock::now();
- for(int i = 0; i < 3000; i++)
- shared_ptr<Test> sp(new Test(10, "This is simple test", 2.3334));
- correlaction
- chrono::system_clock::time_point end = chrono::system_clock::now();
- cout<<"nndouble allocation of 3000 objects took "
- <<chrono::duration_cast<chrono::microseconds>(end - start).count()
- <<"us.n";
- }
- int main(){
- singleAllocation();
- doubleAllocation();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement