#include <sys/time.h>
#include <math.h>       /* for sin, exp etc.           */
#include <stdio.h>      /* standard I/O                */
#include <string.h>     /* for strcpy - 3 occurrences  */
#include <stdlib.h>     /* for exit   - 1 occurrence   */
#include <time.h>
#include <ctype.h>


char e2[32500]; /* ~64MB array with 1 byte char systems */
int ae1 = 32500;

struct timeval starttime,endtime;
#define LOOPS 3 

/* char alphabet1[26]; */

/* setup the array with the alphabet */
/* abcdefghijklmnopqrstuvwxyz */
char alphabet1[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
double te0, te1, prob0;
double lsalu;
long testno;

/* Converting between lower/uppercase */
int Problem0() {
        printf("\nRunning ALU tests(1 for now)...\n");
	printf("\tPreparing test. setting up 64MB char array...\n");	
		for(i=0; i < ae1; i++) {  
			e2[i] = alphabet1[i % 26]; 
			}
		printf("\tdone.\n");
	/*	printf("0 =: %c\n", e2[0]);
		printf("32499 =: %c\n", e2[32499]);
		printf("26 =: %c\n", e2[26]);
		e2[0]=(char)toupper((int)e2[0]);
		printf("0 =: %c\n", e2[0]);
		e2[0]=(char)tolower((int)e2[0]);
		printf("0 =: %c\n", e2[0]); */
		
		printf("\tTest running...\n\n");
		gettimeofday(&starttime, NULL);
		for(testno=0; testno<LOOPS; testno++) {
        		for(i=0;i<strlen(e2);i++){
        			e2[i]=(char)toupper((int)e2[i]);
        		}
        		for(i=0;i<strlen(e2);i++){
        			e2[i]=(char)tolower((int)e2[i]);
        		}
		}	


	gettimeofday(&endtime, NULL);
        te0=((double)(endtime.tv_sec*1000000-starttime.tv_sec*1000000+endtime.tv_usec-starttime.tv_usec))/1000000;
	te1 = 3 * ae1 * 2 / te0;
        printf("\tTest #1:\t ctype.h case modification: %lf/s\n", te1);
	printf("\n\tdone.\n");
	prob0 = 3 * ae1 * 2  / te0;
return prob0;
}
