C 練習例93

C言語の古典100例

問題:時間関数の例2

プログラム分析:なし。

プログラムソースコード:

//  Created by www.example.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;
}

上記の例の実行出力結果は以下のとおりです:

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

C言語の古典100例

その他の拡張