You are on page 1of 1

#include <iostream>

#include <vector>
#include <chrono>
using namespace std;

void insSort(vector<int>& A) {
for(int i=1; i< A.size(); i++) {
int tmp= A[i];
int j= i-1;
while(j>=0 && tmp>A[j]) {
A[j+1]= A[j];
j--;
}
A[j+1]= tmp;
}
}

void time(vector<int>& A){

using std::chrono::high_resolution_clock;
using std::chrono::duration_cast;
using std::chrono::duration;
using std::chrono::nanoseconds;

auto t1= high_resolution_clock::now( );


insSort(A);
auto t2= high_resolution_clock::now( );

auto nanoint1= duration_cast<nanoseconds>(t2-t1);


cout<< nanoint1.count()<<"ns"<<endl;

int main( ) {

int num,i;
vector<int> A = {3, 4, 6, 8, 9};
vector<int> B = {9, 6, 8, 4};
vector<int> C = {3, 6, 4, 1, 5, 7};
vector<int> D = {7, 3, 4, 2, 8, 9, 1};
vector<int> E = {2, 5, 1};

time(A);
time(B);
time(C);
time(D);
time(E);

return 0;
}

You might also like