add speedup for sequential / parallel for bubble and merge sort.

This commit is contained in:
K
2026-04-29 02:15:13 +05:30
parent e29a85dafc
commit 7b797250ea
+14 -4
View File
@@ -151,34 +151,44 @@ int main() {
arr[i] = rand() % 10000;
double start, end;
double time_seq_bubble, time_par_bubble;
double time_seq_merge, time_par_merge;
// --- Sequential Bubble Sort ---
vector<int> seqArr = arr;
start = omp_get_wtime();
sequentialBubbleSort(seqArr);
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 ---
vector<int> parArr = arr;
start = omp_get_wtime();
parallelBubbleSort(parArr);
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 ---
seqArr = arr;
start = omp_get_wtime();
sequentialMergeSort(seqArr, 0, n - 1);
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 ---
parArr = arr;
start = omp_get_wtime();
parallelMergeSort(parArr, 0, n - 1);
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;
}