When we run the program, you can simply use the run-time clock function of the present exemplary test procedure :( microseconds to output)
https://github.com/yaowenxu/Workplace/blob/master/timer/clocktimer.c
/ * * * Author: Yaowen Xu * Github: https://github.com/yaowenxu * Organization: Northern Institute for System Architecture * a Date: 2019-08-18 11:59:54 * LastEditTime: 2019-08-18 12 : 45: 45 * the Description: C language standard library function clock time to test run * / #include <time.h> #include <stdio.h> #include <math.h> int str2int ( char * STR) { char * P = STR; int SUM = 0 ; the while (* = P! ' \ 0 ' ) { SUM = SUM * 10 + (*p-'0'); p++; } return sum; } int main(int argc, char* argv[]){ clock_t start, stop; int def = 1000; if (argc == 2) { def = str2int(argv[argc-1]); } start = clock(); for (int i = 0; i < def ; i++) { a float tmp = sqrt (I); } STOP = Clock (); Double Total = STOP - Start; // use run time printf ( " Clocks: .1f% \ n- " , Total); // clock used altogether printf ( " time: US .1f% \ n- " , Total * 1e6 / (CLOCKS_PER_SEC)); // convert runtime microseconds return 0 ; } / * * Used by approximates The time Processor The Program, * operating since The Beginning of Implementation-defined Time AN * IS Related to that period at The Program Invocation. * its measure the To The A Program Time in the spent, Call The Clock () * function at the start of the program, and subtract its * returned value from the value returned by subsequent calls * to clock(). Then, to obtain the time in seconds, divide * the value returned by clock() by CLOCKS_PER_SEC. * * If you use the system() function in your program, do not * rely on clock() for program timing, because calls to system() * may reset the clock. * * In a multithread POSIX C application, if you are creating threads * with a function that is based on a POSIX.4a draft standard, * the clock() function is thread-scoped. * * Refer:https://www.ibm.com/support/knowledgecenter/en/SSLTBW_2.3.0/com.ibm.zos.v2r3.bpxbd00/clock.htm */
Stay updated, more articles, please pay attention cnblogs.com/xuyaowen