-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment1.cpp
More file actions
43 lines (32 loc) · 1.31 KB
/
Assignment1.cpp
File metadata and controls
43 lines (32 loc) · 1.31 KB
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
#include <iostream>
#include <vector>
#include <time.h>
#include <chrono>
using namespace std;
void PushBack(vector<int> *);
int main(int argc, char** argv) {
vector<int> numbers(0);
cout << "Vector size : "<< numbers.size()<<"\nVector capacity : " << numbers.capacity() <<"\n\n===\n"<< endl;
// Initializing x
int x = 0;
auto startFull = chrono::high_resolution_clock::now();
for(int i = 0; i < 100; i++){
auto startOne = chrono::high_resolution_clock::now();
PushBack(&numbers);
auto stopOne = chrono::high_resolution_clock::now();
auto durationOne = chrono::duration_cast<chrono::nanoseconds>(stopOne - startOne);
cout << "For iteration " << i << " : " << durationOne.count() << "ns" << endl;
}
auto stopFull = chrono::high_resolution_clock::now();
auto durationFull = chrono::duration_cast<chrono::nanoseconds>(stopFull - startFull);
cout << "\n-----\n\nFull execution time \n\n\tNanoseconds : " << durationFull.count() << "ns\n\tSeconds: "<<durationFull.count() / 1000000000.0 << "s"<< endl;
cout << "\n===\n\nVector size : "<< numbers.size()<<"\nVector capacity : " << numbers.capacity() << endl;
return 0;
}
void PushBack(vector<int> * list){
for(int i = 0; i<100; i++){
srand(time(NULL));
int x = rand() % 10 + 1;
list->push_back(x);
}
}