#include <stdio.h>
#include <sys/times.h>
#include <sys/types.h>
#include <time.h>

double get_seconds () {
    struct tms rusage;
    times(&rusage);
    return (double) (rusage.tms_utime)/CLK_TCK;
}

int main (int argc, char *argv[])
{
  char name [300];
  FILE *fp;
  double time_started, time_finished;
  int i, num_files;

  if (argc == 2) {
    num_files = atoi (argv[1]);
  } else {
    printf ("Usage: file num_files\n");
    exit (-1);
  }

  time_started = get_seconds ();

  for (i=0; i<num_files; i++) {
    sprintf (name, "junk_file%d", i);
    fp = fopen (name, "w");
    fprintf (fp, "This is the contents of file %d\n", i);
    fclose (fp);
  }

  time_finished = get_seconds ();

  printf ("Elapsed time %lf\n", time_finished - time_started);
}
