The test run time - time runtime function implementation in the second stage use libc

c standard library, there are time function, it can return to the time difference to now the number of seconds, we can call two of January 1, 1970 to calculate the running time:

https://github.com/yaowenxu/Workplace/blob/master/timer/timetimer.c

NAME
     time -- get time of day

LIBRARY
     Standard C Library (libc, -lc)

SYNOPSIS
     #include <time.h>

     time_t
     time(time_t *tloc);

DESCRIPTION
     The time() function returns the value of time in seconds since 0 hours, 0 minutes, 0 seconds, January 1, 1970, Coordinated Univer-
     sal Time, without including leap seconds.  If an error occurs, time() returns the value (time_t)-1.

     The return value is also stored in *tloc, provided that tloc is non-null.
time Function Description
/ * * 
 * Author: Yaowen Xu 
 * Github: https://github.com/yaowenxu 
 * Organization: Northern Institute for System Architecture 
 * a Date: 2019-08-18 13:03:53 
 * LastEditTime: 2019-08-18 13 : 14: 33 is 
 * the Description: C language library functions for run time counting in seconds 
 * / 

#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[]){
    time_t start, stop; // time_t aka long 
    int def = 1000;
    if (argc == 2)
    {
        def = str2int(argv[argc-1]);
    }
    start = time(NULL);
    for (int i = 0; I <DEF; I ++ ) 
    { 
        a float tmp = sqrt (I); 
    } 
    STOP =   Time (NULL); 
    time_t Total = STOP - Start; // use run time in seconds 
    the printf ( " the Start:% LD S \ n- " , Start); 
    the printf ( " the Stop: LD% S \ n- " , STOP); 
    the printf ( " Time: LD% S \ n- " , total); // clock used in total 
    return  0 ; 
}

Stay updated, if helpful to you, please click on the recommendation! More knowledge about the C language-related, please pay attention cnblogs.com/xuyaowen

Guess you like

Origin www.cnblogs.com/xuyaowen/p/c-lib-time.html