CNC 22 time control 1201ctime

Improved version (sleeping or not sleeping):

// c22ctime22test1201.cpp: This file contains the "main" function. Program execution will start and end here.
//

//#include <iostream>
#include<stdio.h>//
#include<ctime>
#include<Windows.h>

#define DbClock10()  (double)clock()/10.0
int main()//
{
    double star01 = clock();
    double timeSec = 0.0;
    clock_t oldTimeSec = 0;// clock();

    timeSec = DbClock10();

    int ii = 0;
    for (unsigned long long i = 0; true; ++i) {    // 9999; ++i) {
        
        if(0==i) star01 = DbClock10();// clock();

        if (clock() == oldTimeSec) continue;

        printf("i第%d,:",i,ii);
        printf("第%d 次; ", ii);
        printf("%0.2f :_ ", DbClock10());    // 3f)_: ", DbClock10() );
        timeSec = DbClock10() - star01;
        printf("%0.2f\n", timeSec);

        oldTimeSec = clock();
        
        ++ii;
        if (ii > 20) break;
// Sleep(1);//Every time you work late, you can sleep well
    }//for110true

//    std::cout << "Hello World!\n";
}//main

Improved version:

// c22ctime22test1201.cpp: This file contains the "main" function. Program execution will start and end here.
//

//#include <iostream>
#include<stdio.h>//
#include<ctime>
#include<Windows.h>
#define DbClock10()  (double)clock()/10.0
int main()//
{
    double star01 = clock();
    double timeSec = 0.0;
    clock_t oldTimeSec = 0;// clock();

    timeSec = DbClock10();
    for (int i = 0; i < 20; ++i) {    // 9999; ++i) {
        
        if(0==i) star01 = DbClock10();// clock();

        if (clock() == oldTimeSec) continue;

        printf("第%d 次:",i);
        printf("%0.2f :_ ", DbClock10());    // 3f)_: ", DbClock10() );
        timeSec = DbClock10() - star01;
        printf("%0.2f\n", timeSec);

        oldTimeSec = clock();
        Sleep(1);
    }//for110i

//    std::cout << "Hello World!\n";
}//main



Original
#include<ctime>

#include<stdio.h>

int main() {

    clock_t star01=clock();

    printf("%d\n",star01);    //

    unsigned long int uliN=0;

    star01=clock();

    for(int i=0;i<19;++i) {

        if(0!=i) {

            uliN= clock()-star01;

        }//220if

        else{

            star01=clock();

        }//else220if

        printf("%d\n",uliN);

    }//for110i

}//main

28662

0

3

6

8

11

Simplified version:

#include<ctime>

#include<stdio.h>

int main() {

    clock_t star01=clock();

    printf("%d\n",star01); //

    unsigned long int uliN=0;

    star01=clock();

    for(int i=0;i<19;++i) {

//        if(0!=i) {

            uliN= clock()-star01;

// }//220if

/*        else{

            star01=clock();

        }//else220if

        */

        printf("%d\n",uliN);

    }//for110i

}//main

The running results are almost the same, that is, the difference between the occurrence of time 0 and the absence of time 0

29416

2

5

7

11

13

15

18

20

23

25

27

Guess you like

Origin blog.csdn.net/aw344/article/details/128425022