I am making a program template that will allow for me to handle multiple test cases, and I would like to record the amount of time it takes to compute each testcase. I want to exclude the time it takes to type input however. I don't really want to fit in the time recording code inside the solve function and place my input code before it, since it seems a bit troublesome and untidy.
Here is an example:
void solve(int tc) {
int n; cin >> n; // I want to start checking the time it takes between here.
vector<int> a(1000,n);
cout << accumulate(a.begin(),a.end(),0);
cout << "
"; // and here
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int tc; cin >> tc;
int ogtc = tc;
while(tc--)
{
// what I have already tried
#ifdef RON0PC
auto begin = std::chrono::high_resolution_clock::now();
#endif
solve(ogtc-tc);
#ifdef RON0PC
auto end = std::chrono::high_resolution_clock::now();
cout << setprecision(4) << fixed;
cout << "Execution time: " << std::chrono::duration_cast<std::chrono::duration<double>>(end - begin).count() << " seconds" << endl;
#endif
}
return 0;
}
question from:
https://stackoverflow.com/questions/65910224/record-execution-time-excluding-cin 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…