c 标准库中,有time 函数,可以返回 1970年1月1日 开始到现在的秒数,我们可以调用两次的时间差来计算程序运行时间:
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.