I did a quick sanity check using this structure (which has size 576 when int is 32-bit)
struct test
{
int value;
char data[572];
};
I initialized a dynamically allocated array of 1 million structs with this code
for ( int i = 0; i < count; i++ )
{
array[i].value = rand();
for ( int j = 0; j < 572; j++ )
array[i].data[j] = rand();
}
And I sorted the array with this code
int compare( const void *ptr1, const void *ptr2 )
{
struct test *tptr1 = (struct test *)ptr1;
struct test *tptr2 = (struct test *)ptr2;
return tptr1->value - tptr2->value;
}
int main( void )
{
int count = 1000000;
...
qsort( array, count, sizeof(struct test), compare );
...
}
The time to initialize the array was 4.3 seconds, and the time to sort the array was 0.9 seconds.
I then modified the code to create an array of pointers to the structures, and sorted the pointer array. The initialization time was still 4.3 seconds (most of the initialization time is due to calling rand() 500 million times). Sorting the pointer array took 0.4 seconds. Sorting the pointer array was more than twice as fast as sorting the structure array directly.
So my conclusion is that your code has some massive inefficiencies that have nothing to do with qsort.
time(3)before and after the sort method is calledqsortwill move the structs (if that's what you told it to do). You need to show the code. In particular, if the time is spent in the comparison function is large compared to the time to move a structure, then the pointer array won't help anything.