-
Notifications
You must be signed in to change notification settings - Fork 0
/
sorttests.cpp
54 lines (43 loc) · 1.7 KB
/
sorttests.cpp
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
#include <cassert>
#include <algorithm>
#include <chrono>
#include <iostream>
#include <list>
#include <numeric>
#include "list.hpp"
int main()
{
decltype(std::chrono::high_resolution_clock::now()) start, end;
// Prepare
std::list<int> l1(100000);
std::iota(l1.rbegin(), l1.rend(), 0);
xl::list l2(xl::from_range, l1);
xl::list l3(xl::from_range, l1);
xl::list l4(xl::from_range, l1);
// Measure
start = std::chrono::high_resolution_clock::now();
l1.sort();
end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> const std_sort_time(end - start);
start = std::chrono::high_resolution_clock::now();
l2.sort();
end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> const xl_sort_time(end - start);
start = std::chrono::high_resolution_clock::now();
l3.sort<1>();
end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> const xl_sort_time2(end - start);
start = std::chrono::high_resolution_clock::now();
l4.sort<2>();
end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> const xl_sort_time3(end - start);
// Print the results
std::cout << "std::sort time: " << std_sort_time.count() << " seconds" << std::endl;
std::cout << "xl::sort time: " << xl_sort_time.count() << " seconds" << std::endl;
std::cout << "xl::sort2 time: " << xl_sort_time2.count() << " seconds" << std::endl;
std::cout << "xl::sort3 time: " << xl_sort_time3.count() << " seconds" << std::endl;
assert(std::equal(l1.begin(), l1.end(), l2.begin(), l2.end()));
assert(std::equal(l1.begin(), l1.end(), l3.begin(), l3.end()));
assert(std::equal(l1.begin(), l1.end(), l4.begin(), l4.end()));
return 0;
}