-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDefault.cpp
48 lines (40 loc) · 1.1 KB
/
Default.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
#define BASE_SIZE 1000
#define NO_OF_TIMES 500000
class MyPracticalClass
{
public:
int a, b;
MyPracticalClass(int a, int b)
{
MyPracticalClass::a = a;
MyPracticalClass::b = b;
}
};
int main()
{
// unsync the I/O of C and C++.
ios_base::sync_with_stdio(false);
auto start = chrono::high_resolution_clock::now();
MyPracticalClass *arra[BASE_SIZE];
//performing 1000 allocation and deletion * 500000 times
// 1 Billion operations
for (int i = 0; i < NO_OF_TIMES; i++)
{
for (int j = 0; j < BASE_SIZE; j++)
{
arra[j] = new MyPracticalClass(i,j);
}
for (int j = 0; j < BASE_SIZE; j++)
{
delete arra[j];
}
}
// Recording end time.
auto end = chrono::high_resolution_clock::now();
// Calculating total time taken by the program.
cout << "Time taken by Overloaded allocaters/deallocaters is : " << chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << " ms" << endl;
return 0;
}