blob: 3434d7ff7848fa90fdfa1675c107a5f0c76a6e3a (
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
|
#include <algorithm>
#include <cstdlib>
#include <ctime>
#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(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: " << time << "s\n";
}
|