Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
127 views
in Technique[技术] by (71.8m points)

c++ - Record execution time excluding cin

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...