#define MAXLEN 100000
#include <stdio.h>

/*
 *  Show poor Solaris qsort performance
 *  1) compile standalone        : gcc -o testqsort0 testqsort.c
 *  2) then with Freebsd qsort.c : gcc -o testqsort1 qsort.c testqsort.c
 *
 *  compare the speed difference
 *
 *  time ./testqsort0 (3minutes)
 *  time ./testqsort1 (1second)
 *
 *  Caveats :
 *  Better use gcc to compile this guy...
 */

int sortfunc( void* n1, void* n2 ) {
	return ( (*(int*)n1) -(*(int*)n2) );
}


/*
 * What is happening here ?
 * 
 * an array of MAXLEN elements is populated with 1,2,3,1,2,3....
 */
main(int argc, char** argv ) {

	int array[MAXLEN];	
	int i;
	int j = 0;

	for ( i = 0; i < MAXLEN; i++ ) {
		if ( j == 3 ) {
			j = 1;
		} else {
			j++;
		}
		array[i] = j;
	}

	qsort( array, MAXLEN, sizeof(int),sortfunc);
	
}

