#include <stdio.h>
#include <assert.h>
#include <sys/timeb.h>
#include <time.h>

 
//timing macros
#undef PROFILE
#define PROFILE
#ifdef PROFILE

FILE *logfp, *recfp;
static _timeb tbuf;

#define START_PROFILE { recfp = fopen("recording.dat","wb");	assert(recfp != NULL); ENTER(0); }
#define STOP_PROFILE  { LEAVE(0); fclose(recfp); }


#define ENTER(x) { _ftime(&tbuf); fprintf(recfp,"E %d %d %d\n",(x),tbuf.time, tbuf.millitm); }
#define LEAVE(x) { _ftime(&tbuf); fprintf(recfp,"L %d %d %d\n",(x),tbuf.time, tbuf.millitm); }

#else

#define ENTER(x)
#define LEAVE(x)
#endif



main()

{
   int i,j;

   START_PROFILE;

   ENTER(1)
   for (int t = 0; t<10; t++){
      puts("hello");
      ENTER(2)
      for (i=0; i< 10000000; i++) j=i+1;
      puts("world");
      LEAVE(2);
      ENTER(3)
      for (i=0; i< 20000000; i++) j=i+1;
      puts("one");
      LEAVE(3);
      ENTER(4)
      for (i=0; i< 40000000; i++) j=i+1;
      puts("two");
      LEAVE(4);
      ENTER(5)
      for (i=0; i< 80000000; i++) j=i+1;
      puts("three");
      LEAVE(5)
   }
   LEAVE(1);
   
   STOP_PROFILE;

   return 0;
}
