ARTS-S c language program run time statistics

#include <stdio.h>
#include <sys/time.h>
#include <unistd.h>

int main() {
    struct timeval start, end;
    gettimeofday(&start, NULL);
    sleep(2);
    gettimeofday(&end, NULL);
    long seconds = end.tv_sec - start.tv_sec;
    long micros = end.tv_usec - start.tv_usec;
    printf("Time elpased is %f s.\n", ((float)micros) / 1000000 + seconds);
    return 0;
}

Guess you like

Origin www.cnblogs.com/zhouyang209117/p/11226244.html