aboutsummaryrefslogtreecommitdiff
path: root/sort-benchmark/integers/sort_parallel.cpp
blob: 5de41581667142b56fe171e568bad8ce0deaad98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/* Requires Thread Building Blocks (libtbb-dev on Debian) */

#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <execution>
#include <iostream>

int a[ARRAYSIZE];

int main(void) {
	srand(time(NULL));
	for (auto &x : a) x = rand() % 1000000000;

	struct timespec begin;
	clock_gettime(CLOCK_MONOTONIC, &begin);

	std::sort(std::execution::par, a, a+ARRAYSIZE,
		[](const int &x, const int &y) { return x < y; });

	struct timespec end;
	clock_gettime(CLOCK_MONOTONIC, &end);
	double time = end.tv_sec - begin.tv_sec +
		(end.tv_nsec - begin.tv_nsec) / 1000000000.0;

	std::cout << "(" << a[ARRAYSIZE/2] << ") C++ time for " << ARRAYSIZE
		<< " numbers (parallel): " << time << "s\n";
}

Generated with cgit - Back to sebastiano.tronto.net