Runtime of a code snippet with precision greater than 0.001 seconds

0

I need to compute the runtime of sorting algorithms. I've done the following:

steady_clock::time_point t3 = steady_clock::now();  
quickSort(v, 0, n - 1);  
steady_clock::time_point t4 = steady_clock::now();  
duration<double> time_span = duration_cast<duration<double,nano>>(t4 - t3);

The problem is that for time I can not compute times less than 0.001 seconds, the value of time_span appears equal to 0.

    
asked by anonymous 09.04.2018 / 17:16

1 answer

0

I think the problem is on the line

duration<double> time_span = duration_cast<duration<double,nano>>(t4 - t3);

You forgot to std::nano and you lowered the resolution to seconds. That's why I prefer to use auto in these cases. Try replacing with

  auto time_span = duration_cast<duration<double, nano>>(t4 - t3);
    
09.04.2018 / 19:42