Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // https://drive.google.com/drive/folders/1GK3t7PBsRFQp01ApEmk1wb6Scrw_CFA4?usp=sharing
- #include <iostream>
- #include <vector>
- #include <ctime>
- #include <cmath>
- #include <ppl.h>
- using namespace std;
- #define N 50'000'000
- #define EPS 1e-9
- size_t fun(double x)
- {
- double x_2 = x * x;
- return size_t(4e9 * x_2 / (1 + x_2) * sin(x));
- }
- vector<size_t> res1(N + 7), res2(N + 7), res3(N + 7), res4(N + 7);
- int main()
- {
- setlocale(LC_ALL, "Russian");
- for (int i = 0; i < N; ++i)
- res1[i] = res2[i] = res3[i] = res4[i] = fun(i);
- auto t_start = clock();
- sort(res1.begin(), res1.end());
- auto t_end = clock();
- double time1 = 1.0 * (t_end - t_start) / CLOCKS_PER_SEC;
- cout << "Последовательная реализация: " << time1 << "\n";
- t_start = clock();
- concurrency::parallel_sort(res2.begin(), res2.end());
- t_end = clock();
- double time2 = 1.0 * (t_end - t_start) / CLOCKS_PER_SEC;
- cout << "Параллельная реализация (parallel_sort): " << time2 << "\n";
- cout << "Разница во времени: " << time1 / time2 << "\n";
- t_start = clock();
- concurrency::parallel_buffered_sort(res3.begin(), res3.end());
- t_end = clock();
- double time3 = 1.0 * (t_end - t_start) / CLOCKS_PER_SEC;
- cout << "Параллельная реализация (parallel_radix_sort): " << time3 << "\n";
- cout << "Разница во времени: " << time1 / time3 << "\n";
- t_start = clock();
- concurrency::parallel_radixsort(res4.begin(), res4.end());
- t_end = clock();
- double time4 = 1.0 * (t_end - t_start) / CLOCKS_PER_SEC;
- cout << "Параллельная реализация (parallel_radix_sort): " << time3 << "\n";
- cout << "Разница во времени: " << time1 / time4 << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement