While-loop ends the loop, but takes a long time to start the next loop

I program in C ++ and implement a large-scale algorithm in the field of optimization. I have a huge cycle with many things inside it. A loop condition is simply a comparison of two integers aand b. I report time at two points:

1- when the program reaches the end of the while loop.

2- when the program is at the beginning of the while loop.

The code is as follows

        while (a<b){
            //Report time at the beginning of the loop
            time_t beginT = time(0);
            char* dtBegin = ctime (&beginT);
            cout << "Time at the beginning of the loop: " << dtBegin << endl;
            .
            .
            . //all of the other functions inside the loop
            //Report time at the end of the loop
            time_t endT = time(0);
            char* dtEnd = ctime (&endT);
            cout << "Time at the end of the loop: " << dtEnd << endl;
        }

when the program reaches the end of the cycle, it takes a long time to return to the beginning of the cycle, that is, for large input instances it may take about 20 minutes. I must emphasize that all operations inside the cycle are performed and the time is reported, and this is 20 minutes - this is just so that the program returns to the beginning of the cycle.

, ?

.

P.S. , .

+4
1

, . :

    while (a<b){
        //Report time at the beginning of the loop
        time_t beginT = time(0);
        char* dtBegin = ctime (&beginT);
        cout << "Time at the beginning of the loop: " << dtBegin << endl;
        {
            .
            .
            . //all of the other functions inside the loop
        }
        //Report time at the end of the loop
        time_t endT = time(0);
        char* dtEnd = ctime (&endT);
        cout << "Time at the end of the loop: " << dtEnd << endl;
    }

, , , .

+3

Source: https://habr.com/ru/post/1616990/


All Articles