sort.c
/*
 * runSort - run each sort with increasing array sizes
 */
run each sort with increasing array sizes
run each sort with increasing array sizes
void runSort(SORT_FUNCTION fn, const char *name, 
	     int min, int max, int step, int test) {
  int howBig;
  srandom(1);
  if (test) {
    testSort(fn, name);
  }
  else {
    howBig = min;
    do {
      int j;
      struct timeval start, end;
      double diff;
      for (j = 0; j < howBig; j++)
	array[j] = random();
      gettimeofday(&start, 0);
      (*fn)(array, howBig);
      gettimeofday(&end, 0);
      diff = (end.tv_sec - start.tv_sec) + 
	(double)(end.tv_usec-start.tv_usec)/1e6;
      printf("%-10s %8d  %g\n", name, howBig, diff);
      howBig += step;
    } while (howBig <= max);
  }
}
void runSort ( SORT_FUNCTION fn , const char * name , int min , int max , int step , int test ) { int howBig ; srandom ( 1 ) ; if ( test ) { testSort ( fn , name ) ; } else { howBig = min ; do { int j ; struct timeval start , end ; double diff ; for ( j = 0 ; j < howBig ; j ++ ) array [ j ] = random ( ) ; gettimeofday ( & start , 0 ) ; ( * fn ) ( array , howBig ) ; gettimeofday ( & end , 0 ) ; diff = ( end . tv_sec - start . tv_sec ) + ( double ) ( end . tv_usec - start . tv_usec ) / 1e6 ; printf ( " \n " , name , howBig , diff ) ; howBig += step ; } while ( howBig <= max ) ; } }
runSort - run each sort with increasing array sizes
runSort - run each sort with increasing array sizes
/* make sure we start the same each time */ /* initialize the array of numbers to sort */