47 int main(
int argc,
char* argv[]) {
49 return jb::testing::microbenchmark_group_main<config>(
50 argc, argv, create_testcases());
60 std::chrono::microseconds
const expected_delay(1250);
61 std::chrono::microseconds
const sampling_period(10);
77 template <
typename timeseries_type>
80 explicit fixture(
int n_timeseries)
81 : fixture(nsamples, n_timeseries) {
83 fixture(
int size,
int n_timeseries)
85 , va_(n_ts_, timeseries_type(size))
86 , vb_(n_ts_, timeseries_type(size))
87 , estimator_(va_[0], vb_[0])
91 timeseries_type a(size), b(size);
95 a, expected_delay, sampling_period);
97 for (
int i = 0; i != n_ts_; ++i) {
104 for (
int i = 0; i != n_ts_; ++i) {
105 estimator_.estimate_delay(confidence_, tde_, va_[i], vb_[i], sum2_);
107 return static_cast<int>(n_ts_ * va_.size());
110 using vector_timeseries_type =
typename std::vector<timeseries_type>;
112 using confidence_type =
typename tested_type::confidence_type;
113 using estimated_delay_type =
typename tested_type::estimated_delay_type;
114 using sum2_type =
typename tested_type::sum2_type;
120 vector_timeseries_type va_;
123 vector_timeseries_type vb_;
125 tested_type estimator_;
127 confidence_type confidence_;
129 estimated_delay_type tde_;
140 template <
typename T,
typename A>
141 class fixture<boost::multi_array<T, 2, A>> {
143 explicit fixture(
int n_timeseries)
144 : fixture(nsamples, n_timeseries) {
146 fixture(
int size,
int n_timeseries)
147 : a_(boost::extents[n_timeseries][size])
148 , b_(boost::extents[n_timeseries][size])
156 a_, expected_delay, sampling_period);
161 estimator_.estimate_delay(confidence_, tde_, a_, b_, sum2_);
162 return static_cast<int>(a_.shape()[0] * a_.shape()[1]);
165 using timeseries_type = boost::multi_array<T, 2, A>;
167 using confidence_type =
typename tested_type::confidence_type;
168 using estimated_delay_type =
typename tested_type::estimated_delay_type;
169 using sum2_type =
typename tested_type::sum2_type;
174 tested_type estimator_;
175 confidence_type confidence_;
176 estimated_delay_type tde_;
189 template <
typename vector_type>
190 std::function<void(config const&)> test_case() {
191 return [](config
const& cfg) {
193 benchmark bm(cfg.microbenchmark());
194 auto r = bm.
run(cfg.n_timeseries());
195 bm.typical_output(r);
202 {
"float:aligned:many",
203 test_case<jb::fftw::aligned_multi_array<float, 2>>()},
204 {
"float:aligned:single", test_case<jb::fftw::aligned_vector<float>>()},
205 {
"double:aligned:many",
206 test_case<jb::fftw::aligned_multi_array<double, 2>>()},
207 {
"double:aligned:single", test_case<jb::fftw::aligned_vector<double>>()},
208 {
"float:unaligned:many", test_case<boost::multi_array<float, 2>>()},
209 {
"float:unaligned:single", test_case<std::vector<float>>()},
210 {
"double:unaligned:many", test_case<boost::multi_array<double, 2>>()},
211 {
"double:unaligned:single", test_case<std::vector<double>>()},
212 {
"complex:float:aligned:many",
213 test_case<jb::fftw::aligned_multi_array<std::complex<float>, 2>>()},
214 {
"complex:float:aligned:single",
215 test_case<jb::fftw::aligned_vector<std::complex<float>>>()},
216 {
"complex:double:aligned:many",
217 test_case<jb::fftw::aligned_multi_array<std::complex<double>, 2>>()},
218 {
"complex:double:aligned:single",
219 test_case<jb::fftw::aligned_vector<std::complex<double>>>()},
220 {
"complex:float:unaligned:many",
221 test_case<boost::multi_array<std::complex<float>, 2>>()},
222 {
"complex:float:unaligned:single",
223 test_case<std::vector<std::complex<float>>>()},
224 {
"complex:double:unaligned:many",
225 test_case<boost::multi_array<std::complex<double>, 2>>()},
226 {
"complex:double:unaligned:single",
227 test_case<std::vector<std::complex<double>>>()},
233 #ifndef JB_FFTW_DEFAULT_bm_time_delay_estimator_many_test_case 234 #define JB_FFTW_DEFAULT_bm_time_delay_estimator_many_test_case \ 236 #endif // JB_FFTW_DEFAULT_bm_time_delay_estimator_many_test_case 238 #ifndef JB_FFTW_DEFAULT_bm_time_delay_estimator_many_n_timeseries 239 #define JB_FFTW_DEFAULT_bm_time_delay_estimator_many_n_timeseries 1 240 #endif // JB_FFTW_DEFAULT_bm_time_delay_estimator_many_n_timeseries 242 std::string
const test_case =
244 int constexpr n_timeseries =
250 : log(desc(
"log",
"logging"), this)
252 desc(
"microbenchmark",
"microbenchmark"), this,
253 jb::testing::microbenchmark_config().test_case(
defaults::test_case))
257 "Number of timeseries as argument to compute TDE. " 258 "If microbenchmark.test_case is *:single, the fixture " 259 "executes this many calls " 260 " to compute TDE passing a container with one time series as " 261 "argument every time. " 262 "If it is *:many, the fixture uses a 2-dimension array " 264 "many time series as argument to a one time compute TDE."),
268 void config::validate()
const {
270 microbenchmark().validate();
271 if (n_timeseries() < 1) {
272 std::ostringstream os;
273 os <<
"n_timeseries must be > 0 (" << n_timeseries() <<
")";
Define defaults for program parameters.
timeseries_t delay_timeseries_periodic(timeseries_t const &ts, duration_t delay, duration_t sampling_period)
Delay a timeseries using a periodic extension for early values.
Base class for all configuration objects.
virtual void validate() const
Validate the settings.
auto sum_square(container_t const &ts)
Compute the sum square of a family of timeseries.
results run(Args &&... args)
Run the microbenchmaark.
std::map< std::string, std::function< void(config const &cfg)> > microbenchmark_group
Define a representation for a group of microbenchmarks.
void create_triangle_timeseries(int nsamples, timeseries &ts)
Create a simple timeseries where the values look like a triangle.
A time delay estimator based on cross-correlation.
#define config_object_constructors(NAME)
Helper class to easily define configuration attributes.
A simple class to communicate the result of parsing the options.
#define JB_FFTW_DEFAULT_bm_time_delay_estimator_many_test_case
std::size_t nsamples(container_type const &a)
Count the elements in the last dimension of a vector-like container.
#define JB_FFTW_DEFAULT_bm_time_delay_estimator_many_n_timeseries
Run a micro-benchmark on a given class.
int main(int argc, char *argv[])
The top-level namespace for the JayBeams library.