//
// This program is from:
//  answered Jan 27, 2010 at 21:21
//  Daniel Vassallo
// https://stackoverflow.com/questions/2150291/how-do-i-measure-a-time-interval-in-c
//
#include <stdio.h>
#include <sys/time.h>                // for gettimeofday()

int main(void)
{
    struct timeval t1, t2;
    double elapsedTime;

    // start timer
    gettimeofday(&t1, NULL);

    // do something
    // ...
    // (Begin added code here)

    for (int i=0; i<100; i++)
      printf("Hello world!\n");
    // (End added code here)

    // stop timer
    gettimeofday(&t2, NULL);

    // compute and print the elapsed time in millisec
    elapsedTime = (t2.tv_sec - t1.tv_sec) * 1000.0;      // sec to ms
    elapsedTime += (t2.tv_usec - t1.tv_usec) / 1000.0;   // us to ms
    printf("%f ms.\n", elapsedTime);
}
