aboutsummaryrefslogtreecommitdiff
path: root/sort-benchmark/integers/sort.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sort-benchmark/integers/sort.cpp')
-rw-r--r--sort-benchmark/integers/sort.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/sort-benchmark/integers/sort.cpp b/sort-benchmark/integers/sort.cpp
new file mode 100644
index 0000000..3434d7f
--- /dev/null
+++ b/sort-benchmark/integers/sort.cpp
@@ -0,0 +1,25 @@
1#include <algorithm>
2#include <cstdlib>
3#include <ctime>
4#include <iostream>
5
6int a[ARRAYSIZE];
7
8int main(void) {
9 srand(time(NULL));
10 for (auto &x : a) x = rand() % 1000000000;
11
12 struct timespec begin;
13 clock_gettime(CLOCK_MONOTONIC, &begin);
14
15 std::sort(a, a+ARRAYSIZE,
16 [](const int &x, const int &y) { return x < y; });
17
18 struct timespec end;
19 clock_gettime(CLOCK_MONOTONIC, &end);
20 double time = end.tv_sec - begin.tv_sec +
21 (end.tv_nsec - begin.tv_nsec) / 1000000000.0;
22
23 std::cout << "(" << a[ARRAYSIZE/2] << ") C++ time for " << ARRAYSIZE
24 << " numbers: " << time << "s\n";
25}

Generated with cgit - Back to sebastiano.tronto.net