include<iostream>
include<chrono>
usingnamespace std;
auto t1 = chrono::steady_clock::now();
BoyerMoore(txt,pat);
auto t2 = chrono::steady_clock::now();
auto duration = chrono::duration_cast<chrono::microseconds>(t2-t1);
cout << "Duration: " << duration.count() <<endl;
Here i am trying to get the run time of a certain function. But the output i get is not desirable as I am sure it is incorrect.
output:
Duration: 0
would anyone know how to solve this problem. The program seemed to be running the first few times I ran it, but after rerunning the program after a number of times, the duration would always end up 0.
yep.
If your function executes too fast, you can't register the time with simple approaches.
I used to do it off the cpu clocks, but those actually vary on modern cpu now (they were fixed when we did it). Now you have to do weird stuff like pull it off the north bridge or graphics card or other sources. Or, you can just compare clocks directly (they may change the cpu frequency, but this is how much WORK was done).