home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_08_08 / 8n08070a < prev    next >
Text File  |  1990-07-18  |  737b  |  36 lines

  1.  
  2. #include <stdio.h>
  3. #include <time.h>
  4. #include <stdlib.h>
  5.  
  6. #define ARRAY_SIZE 1000
  7.  
  8. int test_array[ARRAY_SIZE];
  9.  
  10. int compare(int *a,int *b)
  11. {
  12.     return(*a-*b);
  13. }
  14.  
  15. main()
  16. {
  17.     int i;
  18.     time_t start_time;
  19.     time_t stop_time;
  20.  
  21.     for ( i=0 ; i<ARRAY_SIZE ; i++ )
  22.         test_array[i] = rand();
  23.     time( &start_time );
  24.     qsort( test_array, ARRAY_SIZE, sizeof(int), compare );
  25.     time( &stop_time );
  26.     printf( "%f seconds elapsed.\n",
  27.            difftime(stop_time,start_time) );
  28.     for ( i=0; i<ARRAY_SIZE-1 ; i++ )
  29.         if ( test_array[i] > test_array[i+1] )
  30.             printf( "Mismatch at position %d\n", i );
  31. }
  32.  
  33.            A Driver Program to Test Quicksort Performance
  34.            
  35.  
  36.