I want to calculate the running time of a function for my assignment. I keep getting 0 nut my teacher strictly said that he want some non zero value even for a loop of 10 size. My code so far is this
#include <chrono>
using namespace std;
using std::chrono::duration_cast;
using std::chrono::nanoseconds;
using std::chrono::steady_clock;
steady_clock::time_point t1 = steady_clock::now();
for(int i=0;i<times;i++){
bubbleSort(arr,size);
}
steady_clock::time_point t2 = steady_clock::now();
cout<<(float)duration_cast<nanoseconds>(t2-t1).count()/times<<" ";
i have also tried chrono::high_resolution_clock
, clock()
and many others.
The main problem is that i have to give some non zero value for time=1; and size=10
.
Please suggest how could i do this?