add speedup for sequential / parallel for bubble and merge sort.
This commit is contained in:
+14
-4
@@ -151,34 +151,44 @@ int main() {
|
|||||||
arr[i] = rand() % 10000;
|
arr[i] = rand() % 10000;
|
||||||
|
|
||||||
double start, end;
|
double start, end;
|
||||||
|
double time_seq_bubble, time_par_bubble;
|
||||||
|
double time_seq_merge, time_par_merge;
|
||||||
|
|
||||||
// --- Sequential Bubble Sort ---
|
// --- Sequential Bubble Sort ---
|
||||||
vector<int> seqArr = arr;
|
vector<int> seqArr = arr;
|
||||||
start = omp_get_wtime();
|
start = omp_get_wtime();
|
||||||
sequentialBubbleSort(seqArr);
|
sequentialBubbleSort(seqArr);
|
||||||
end = omp_get_wtime();
|
end = omp_get_wtime();
|
||||||
cout << "Sequential Bubble Sort time: " << (end - start) << " seconds" << endl;
|
time_seq_bubble = end - start;
|
||||||
|
cout << "Sequential Bubble Sort time: " << time_seq_bubble << " seconds" << endl;
|
||||||
|
|
||||||
// --- Parallel Bubble Sort ---
|
// --- Parallel Bubble Sort ---
|
||||||
vector<int> parArr = arr;
|
vector<int> parArr = arr;
|
||||||
start = omp_get_wtime();
|
start = omp_get_wtime();
|
||||||
parallelBubbleSort(parArr);
|
parallelBubbleSort(parArr);
|
||||||
end = omp_get_wtime();
|
end = omp_get_wtime();
|
||||||
cout << "Parallel Bubble Sort time: " << (end - start) << " seconds" << endl;
|
time_par_bubble = end - start;
|
||||||
|
cout << "Parallel Bubble Sort time: " << time_par_bubble << " seconds" << endl;
|
||||||
|
|
||||||
|
cout << "Bubble Sort Speedup (Sequential / Parallel) = " << (time_seq_bubble / time_par_bubble) << "x" << endl;
|
||||||
|
|
||||||
// --- Sequential Merge Sort ---
|
// --- Sequential Merge Sort ---
|
||||||
seqArr = arr;
|
seqArr = arr;
|
||||||
start = omp_get_wtime();
|
start = omp_get_wtime();
|
||||||
sequentialMergeSort(seqArr, 0, n - 1);
|
sequentialMergeSort(seqArr, 0, n - 1);
|
||||||
end = omp_get_wtime();
|
end = omp_get_wtime();
|
||||||
cout << "Sequential Merge Sort time: " << (end - start) << " seconds" << endl;
|
time_seq_merge = end - start;
|
||||||
|
cout << "\nSequential Merge Sort time: " << time_seq_merge << " seconds" << endl;
|
||||||
|
|
||||||
// --- Parallel Merge Sort ---
|
// --- Parallel Merge Sort ---
|
||||||
parArr = arr;
|
parArr = arr;
|
||||||
start = omp_get_wtime();
|
start = omp_get_wtime();
|
||||||
parallelMergeSort(parArr, 0, n - 1);
|
parallelMergeSort(parArr, 0, n - 1);
|
||||||
end = omp_get_wtime();
|
end = omp_get_wtime();
|
||||||
cout << "Parallel Merge Sort time: " << (end - start) << " seconds" << endl;
|
time_par_merge = end - start;
|
||||||
|
cout << "Parallel Merge Sort time: " << time_par_merge << " seconds" << endl;
|
||||||
|
|
||||||
|
cout << "Merge Sort Speedup (Sequential / Parallel) = " << (time_seq_merge / time_par_merge) << "x" << endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user