void bench_1() { int i, j; int trials = 5; int *array; long time_sum; printf("\nAlgorithm 1 Benchmarking Begin\n"); for(i=100; i < 901; i += 100) { time_sum = 0; for(j=0; j < trials; ++j) { sleep(.2); //We wait one second to assure random seeds properly array = rand_array(i); //Create new array //Begin benchmarking timer_start(); algo_1(array, i); timer_stop(); time_sum += timer_get_time(); } time_sum = time_sum / trials; //Gets average printf("%d elements took an average %ld microsecs over %d trials\n", i, time_sum, trials); } // We don't need 1000-9000 cases here because that would take forever }
int main() { int test2[] = {22, -27, 38, -34, 49, 40, 13, -44, -13, 28, 46, 7, -26, 42, 29, 0, -6, 35, 23, -37, 10, 12, -2, 18, -12, -49, -10, 37, -5, 17, 6, -11, -22, -17, -50, -40, 44, 14, -41, 19, -15, 45, -23, 48, -1, -39, -46, 15, 3, -32, -29, -48, -19, 27, -33, -8, 11, 21, -43, 24, 5, 34, -36, -9, 16, -31, -7, -24, -47, -14, -16, -18, 39, -30, 33, -45, -38, 41, -3, 4, -25, 20, -35, 32, 26, 47, 2, -4, 8, 9, 31, -28, 36, 1, -21, 30, 43, 25, -20, -42}; int i, j; int trials = 5; int *array; long time_sum; for(i=100; i < 901; i += 100) { time_sum = 0; for(j=0; j < trials; ++j) { sleep(1); //We wait one second to assure random seed array = rand_array(i); //Create new array //Begin benchmarking timer_start(); algo_1(array, i); timer_stop(); time_sum += timer_get_time(); } time_sum = time_sum / trials; printf("%d elements took an average %ld millisecs\n", i, time_sum); } /* We were told we could skip this chunk of testing for this algorithm for(i=1000; i < 9001; i +=1000) { timer_start(); algo_1(rand_array(i), i); timer_stop(); printf("%d elements took %ld millisecs\n", i, timer_get_time()); } */ return 0; }
void analyserLettres(int x1, int y1, int x2, int y2){ cpBB unCpBB; int n=0; char * result=(char *) malloc(sizeof(char) * 255); char * stringBoules=NULL; for(int i=0;i<50;i++) { unCpBB=cpBBNewForCircle(cpv(lesBoules[i].y, lesBoules[i].x ),lesBoules[i].radius); int intersected=cpBBIntersectsSegment(unCpBB, cpv(x1,y1),cpv(x2,y2));; if(intersected==1 && lesBoules[i].del==FALSE) { result[n]=*lesBoules[i].lettre; n++; //printf("%s",result); stringBoules=algo_1(result); if(stringBoules!=NULL){ for(int m=0;m<sizeof(result);m++){ if(*lesBoules[i].lettre==result[m]){ lesBoules[i].del=TRUE; cpSpaceRemoveShape(espace,lesBoules[i].shape); cpSpaceRemoveBody(espace,lesBoules[i].body); nbBoules=nbBoules-1; } } score+=sizeof(stringBoules)/4; printf(" \n %s",stringBoules); } } } free(result); }
int main() { int r=0; FILE *myFile; myFile = fopen(filename, "r"); char newline_buff[2] = "\n"; fp_out = fopen("output.txt", "w"); //read file into array int i=0; if (myFile == NULL) { printf("Error Reading File\n"); exit (0); } int input; int count[fileLines]; while(r<fileLines) { input=0; count[r]=1; if ( (input = fgetc(myFile)) == '[' ) { while ( (input = fgetc(myFile)) != ']' ) { if(input == ',') count[r]++; } r++; } } // for(r=0;r<fileLines;r++) // printf("count = %d\n",count[r]); fclose(myFile); myFile = fopen(filename, "r"); r=0; fputs("Alg.1\tAlg.2\tAlg.3\n", fp_out); while(r<fileLines) { if ( (input = fgetc(myFile)) == '[' ) { int *numberArray = malloc(count[r]*sizeof(int)); while ( (input = fgetc(myFile)) != ']' ) { for (i = 0; i < count[r]; i++) { fscanf(myFile, "%d,", &numberArray[i] ); } } printf("["); for (i = 0; i < count[r]-1; i++) { printf("%d,", numberArray[i]); } printf("%d", numberArray[i]); printf("]\n"); algo_1(numberArray, count[r]); fputs("\t", fp_out); print_max_2(numberArray, count[r]); fputs("\t", fp_out); print_max_3(numberArray, count[r]); fputs("\n", fp_out); free(numberArray); r++; } } fclose(myFile); //Begin Benchmarking benchmarking = TRUE; bench_1(); bench_2(); bench_3(); fclose(fp_out); return 0; }