Yeah, guess I'll have to use brute-force as a last resort. Any other ideas, anyone?
It's going to be hard to implement a million runs of this the way I've structured the code, as I'm using a double-nested for loop.
In the current state the code has 3 kinds of table initialisation (sorted, inverted, random) and 3 sorting algorithms (mergesort, heapsort, counting sort), so the double-nested loop makes sure the to-be sorted table is reinitialized as needed for each run.
Parts of code:
Code:
const int sorts = 3;
const int inits = 3;
const int testruns = 20;
const int number_range = 20000000;
const int my_size = 100 * 1000000;
Code:
int main()
{
int* myarray = new int[my_size];
int size_n = my_size;
// !!! Only uncomment the following line if you want all printed messages to go
// !!! to "mybench.txt" instead of the console! System messages will not be shown
// !!! either, such as the output of (system("PAUSE"))!
//freopen("mybench.txt", "w", stdout);
for (int k=0;k<testruns;k++) {
cout << "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-" << endl;
cout << "Run " << k+1 << " out of " << testruns << endl;
cout << "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-" << endl;
cout << endl;
for (int i=0;i<inits;i++){
switch (i){
case 0:
cout << "***Inverse Fill Init***" << endl << endl;
break;
case 1:
cout << "***Sorted Fill Init***" << endl << endl;
break;
case 2:
cout << "***Random Fill Init***" << endl << endl;
break;
}
for (int j=0;j<sorts;j++){
switch(j){
case 0:
cout << ("MergeSort\n===============================\n");
break;
case 1:
cout << ("HeapSort\n===============================\n");
break;
case 2:
cout << ("Counting Sort\n===============================\n");
break;
}
cout << "Required CPU time in seconds: " << endl;
//for(int k=0;k<10;k++){
initArray(myarray, size_n, i);
doSort(myarray, size_n, j, k, i);
//}
cout << endl;
}
}
}
// Εκτύπωση αποτελεσμάτων σε αρχείο
mybench.setf(ios::fixed, ios::floatfield);
mybench.precision(3);
for(int k=0;k<(inits * testruns);k++){
if (k%testruns==0) mybench << endl;
mybench << c_req_merge[k] << "\t" << c_req_heap[k] << "\t" << c_req_count[k] << endl;
}
/*
system("PAUSE");
printMyArray(myarray, size_n);
*/
delete[] myarray;
//system("PAUSE");
return 0;
}
Code:
void doSort(int myarray[], int size_n, int typeOfSort, int run, int init)
{
clock_t c_bef,c_aft,c_req;
float c_req_f;
c_bef = clock();
switch(typeOfSort){
case 0:
// 0: MergeSort
mergeSort(myarray, myarray, size_n);
break;
case 1:
// 1: heapSort
heapSort(myarray, size_n);
break;
case 2:
// 2: Counting Sort
counting_Sort(myarray, size_n);
break;
}
c_aft = clock();
c_req = c_aft - c_bef;
c_req_f = (float)c_req / (float)CLOCKS_PER_SEC;
cout.setf(ios::fixed, ios::floatfield);
cout.precision(3);
cout << c_req_f << endl;
switch(typeOfSort){
case 0:
c_req_merge[(init * testruns) + run] = c_req_f;
break;
case 1:
c_req_heap[(init * testruns) + run] = c_req_f;
break;
case 2:
c_req_count[(init * testruns) + run] = c_req_f;
break;
}
}