-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench.cpp
55 lines (43 loc) · 1.52 KB
/
bench.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
55
#include "bufradixsort.h"
#include <cstdint>
#include <chrono>
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <memory>
#include <random>
#include <utility>
typedef std::chrono::high_resolution_clock::duration duration_t;
static std::pair<duration_t, duration_t> test_uint32(std::mt19937 gen) {
std::cout << "uint32 test" << std::endl;
size_t len = 200000000;
std::vector<uint32_t> data(len);
std::vector<uint32_t> work1(len);
std::vector<uint32_t> work2(len);
for (size_t i = 0; i < len; i++)
data[i] = gen();
std::copy(data.begin(), data.end(), work1.begin());
bufradix_layout_t elem_layout[] = {{0, BUFRADIX_LAYOUT_UINT, 32}, {0, BUFRADIX_LAYOUT_END, 0}};
auto t1s = std::chrono::high_resolution_clock::now();
bufradixsort(work1.data(), work2.data(), len, elem_layout);
auto t1e = std::chrono::high_resolution_clock::now();
auto d1 = t1e - t1s;
auto t2s = std::chrono::high_resolution_clock::now();
std::sort(data.begin(), data.end());
auto t2e = std::chrono::high_resolution_clock::now();
auto d2 = t2e - t2s;
return std::make_pair(d1, d2);
}
static std::pair<duration_t, duration_t>(*tests[])(std::mt19937) = {
test_uint32,
NULL
};
int main() {
std::mt19937 gen(3145);
for (auto test_p = tests; *test_p; test_p++) {
auto dp = (*test_p)(gen);
std::cout << "bufradixsort " << std::chrono::duration_cast<std::chrono::milliseconds>(dp.first).count() << std::endl;
std::cout << "std::sort " << std::chrono::duration_cast<std::chrono::milliseconds>(dp.second).count() << std::endl;;
}
return 0;
}