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

double getTime(int);

int main(int argc, char *argv[]){
	double start,stop,timeElapsed;
	int resolution;

	if (argc<2){	
		printf ("Usage: getTime s[seconds or m[microseconds]\n");
		exit(1);
	}
	if (*argv[1]=='s')	resolution=1;
	if (*argv[1]=='m')	resolution=-6;
	
	start=getTime(resolution);
	printf ("Hello World!\n");
	stop=getTime(resolution);
	timeElapsed=stop-start;
	printf ("The execution time is %f\n",timeElapsed);
}

double getTime (int resolution){
	double time;
	struct timeval *p;
	int status;

	p=(struct timeval*)malloc(sizeof(struct timeval));	
	status=gettimeofday(p,NULL);
//	if (status!=0)	fprintf(stdout,"Error calling gettimeofday: %s\n",errno);
	if (resolution==1)	time=(p->tv_sec);
	if (resolution==-6)	time=(p->tv_usec);
	
	return(time);
}

