/* demo.c -- demonstrate a performance regression in Linux 2.6.26-2.6.28

   Based on commit 78f707bfc723552e8309b7c38a8d0cc51012e813 in 2.6.29,
   by Jens Axboe and attributing a test case to Sean.White@APCC.com.
*/
#include <stdio.h>
#include <sys/time.h>

const int ROWS = 100;

int main(int argc, char **argv)
{
    int fdes, i;
    FILE *fp;
    struct timeval start;
    struct timeval end;
    struct timeval res;

    gettimeofday(&start, NULL);
    for (i=0; i<ROWS; i++) {
            fp = fopen("test_file", "a");
            fprintf(fp, "Some Text Data\n");
            fdes = fileno(fp);
            fsync(fdes);
            fclose(fp);
    }
    gettimeofday(&end, NULL);

    timersub(&end, &start, &res);
    fprintf(stdout, "time to write %d lines is %ld(msec)\n", ROWS,
                    (res.tv_sec*1000000 + res.tv_usec)/1000);

    return 0;
}
