Easy Tutorial
❮ C Exercise Example31 C Arrays ❯

C Exercise Example 93

C Language Classic 100 Examples

Title: Time Function Example 2

Program Analysis: None.

Program Source Code:

//  Created by www.tutorialpro.org on 15/11/9.
//  Copyright © 2015 tutorialpro.org. All rights reserved.
//

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

int main()
{
    long i = 10000000L;
    clock_t start, finish;
    double TheTimes;
    printf("The time required for %ld empty loops is ", i);
    start = clock();
    while (i--);
    finish = clock();
    TheTimes = (double)(finish - start) / CLOCKS_PER_SEC;
    printf("%f seconds.\n", TheTimes);
    return 0;
}

The output result of the above example is:

The time required for 10000000 empty loops is 0.025367 seconds.

C Language Classic 100 Examples

❮ C Exercise Example31 C Arrays ❯