Latest web development tutorials

C Exercise Example 93

100 cases of classic C language 100 cases of classic C language

Title: Time Functions Example 2

Program Analysis: None.

Source Code:

//  Created by www.w3big.com on 15/11/9.
//  Copyright © 2015年 本教程. All rights reserved.
//

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main()
{
    long i=10000000L;
    clock_t start,finish;
    double TheTimes;
    printf("做%ld次空循环需要的时间为",i);
    start=clock();
    while(i--);
    finish=clock();
    TheTimes=(double)(finish-start)/CLOCKS_PER_SEC;
    printf("%f秒。\n",TheTimes);
    return 0;
}

Run the above example output is:

做10000000次空循环需要的时间为0.025367秒。

100 cases of classic C language 100 cases of classic C language