forked from timsort/cpp-TimSort
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbench_sort.cpp
More file actions
63 lines (53 loc) · 1.79 KB
/
bench_sort.cpp
File metadata and controls
63 lines (53 loc) · 1.79 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* Copyright (c) 2011 Fuji, Goro (gfx) <gfuji@cpan.org>.
* Copyright (c) 2019 Morwenn.
*
* SPDX-License-Identifier: MIT
*/
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <vector>
#include <gfx/timsort.hpp>
#include "benchmarker.hpp"
template <typename value_t>
struct Bench {
void operator()(const std::vector<value_t> &a) const {
{
std::vector<value_t> b(a);
std::clock_t start = std::clock();
for (int i = 0; i < 100; ++i) {
std::copy(a.begin(), a.end(), b.begin());
std::sort(b.begin(), b.end());
}
std::clock_t stop = std::clock();
std::cerr << "std::sort " << (double(stop - start) / CLOCKS_PER_SEC) << std::endl;
}
{
std::vector<value_t> b(a);
std::clock_t start = std::clock();
for (int i = 0; i < 100; ++i) {
std::copy(a.begin(), a.end(), b.begin());
std::stable_sort(b.begin(), b.end());
}
std::clock_t stop = clock();
std::cerr << "std::stable_sort " << (double(stop - start) / CLOCKS_PER_SEC) << std::endl;
}
{
std::vector<value_t> b(a);
std::clock_t start = std::clock();
for (int i = 0; i < 100; ++i) {
std::copy(a.begin(), a.end(), b.begin());
gfx::timsort(b.begin(), b.end());
}
std::clock_t stop = std::clock();
std::cerr << "timsort " << (double(stop - start) / CLOCKS_PER_SEC) << std::endl;
}
}
};
int main(int argc, const char *argv[]) {
const int size = argc > 1 ? std::atoi(argv[1]) : 100 * 1000;
Benchmarker<Bench> benchmarker(size);
benchmarker.run();
}