-
Notifications
You must be signed in to change notification settings - Fork 1
/
benchmark.cpp
135 lines (114 loc) · 3.41 KB
/
benchmark.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#ifndef SSE_S
#ifdef __AVX512F__
#define SSE_S 16
#elif defined __AVX2__
#define SSE_S 8
#elif defined __SSE2__ && defined __SSE4_1__
#define SSE_S 4
#else
#define SSE_S 1
#endif
#endif
#include <iostream> // std::cout
#include <string>
#include <utility>
#include <set>
#include "benchmarking/timing.hpp"
#include "benchmarking/data-generation.hpp"
#include "assert.h"
#include "sw_base.cpp"
#include "sw_windowed.cpp"
#include "sw_parallel_windowed.cpp"
#include "sw_bithacked.cpp"
#include "sw_bithacked_striped.cpp"
#include "sw_simded_alpern.cpp"
#include "sw_multicore_alpern.cpp"
struct base_sw
{
template < typename T >
T operator () ( std::pair< T, T > data ) const
{
sw_base(data);
return "0";
}
};
struct windowed_sw
{
template < typename T >
T operator () ( std::vector<std::pair< T, T >> data ) const
{
sw_windowed(data);
return "0";
}
};
struct parallel_windowed_sw
{
template < typename T >
T operator () ( std::vector<std::pair< T, T >> data ) const
{
sw_parallel_windowed(data);
return "0";
}
};
struct bithacked_sw
{
template < typename T >
T operator () ( std::pair< T, T > data ) const
{
sw_bithacked(data);
return "0";
}
};
struct bithacked_striped_sw
{
template < typename T >
T operator () ( std::vector<std::pair< T, T >> data ) const
{
sw_bithacked_striped(data);
return "0";
}
};
struct simded_alpern_sw
{
template < typename T >
T operator () ( std::vector<std::pair< T, T >> data ) const
{
sw_simded_alpern(data);
return "0";
}
};
struct multicore_alpern_sw
{
template < typename T >
T operator () ( std::vector<std::pair< T, T >> data ) const
{
sw_multicore_alpern(data);
return "0";
}
};
int main(int argc, char** argv)
{
auto num_pairs = 1u << 13;
auto string_len = 1u << 10;
omp_set_num_threads( THRD_CNT );
std::string version(argv[argc - 1]);
std::vector<std::string> versions_list = {
"base", "windowed", "parallel-windowed", "bithacked", "bithacked-striped", "simd-alpern", "multicore-alpern"};
std::set<std::string> versions (versions_list.begin(), versions_list.end());
const bool is_in = versions.find(version) != versions.end();
if (!is_in) std::cout << "Incorrect version provided: " << version << std::endl;
assert (is_in);
// For random numbers, one must first seed the random number generator. This is the idiomatic
// approach for the random number generator libraries that we have chosen.
std::srand ( static_cast< uint32_t >( std::time(0) ) );
auto const test_cases = csc586::benchmark::uniform_rand_vec_of_vec< std::string >( num_pairs, string_len );
auto const run_time = version == "multicore-alpern" ? csc586::benchmark::benchmark_once(multicore_alpern_sw{}, test_cases) :
version == "simd-alpern" ? csc586::benchmark::benchmark_once(simded_alpern_sw{}, test_cases) :
version == "parallel-windowed" ? csc586::benchmark::benchmark_once(parallel_windowed_sw{}, test_cases) :
version == "windowed" ? csc586::benchmark::benchmark_once(windowed_sw{}, test_cases) :
version == "bithacked" ? csc586::benchmark::benchmark(bithacked_sw{}, test_cases) :
version == "bithacked-striped" ? csc586::benchmark::benchmark_once(bithacked_striped_sw{}, test_cases) :
csc586::benchmark::benchmark(base_sw{}, test_cases);
std::cout << "Average time (us): " << run_time << std::endl;
return 0;
}