| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- #include "core/datanode_base.h"
- #include <boost/asio/awaitable.hpp>
- #include <boost/asio/co_spawn.hpp>
- #include <boost/asio/detached.hpp>
- #include <cassert>
- #include <benchmark/benchmark.h>
- using boost::asio::awaitable;
- using boost::asio::co_spawn;
- using boost::asio::detached;
- using namespace sophiar;
- static void BM_timestamp(benchmark::State &state) {
- for (auto _: state) {
- benchmark::DoNotOptimize(sophiar::current_timestamp());
- }
- }
- BENCHMARK(BM_timestamp);
- static void BM_datanode_chain(benchmark::State &state) {
- struct test_type : public datanode_base<high_freq_tag> {
- uint64_t cnt = 0;
- awaitable<bool> exec() {
- auto input_data = get_input_data(0);
- auto output_data = data_packet::new_instance();
- output_data->copy_content(*input_data);
- (*output_data)[0] += 1.0;
- output_data->timestamp = current_timestamp();
- cnt = (*output_data)[0];
- set_output_data(0, output_data);
- co_return true;
- }
- };
- co_spawn(high_freq_context, [&]() -> awaitable<void> {
- auto total = state.range(0);
- auto pool = new test_type[total];
- for (size_t i = 0; i < total; ++i) {
- auto &node = pool[i];
- co_await node.init();
- node.set_trigger_mode(test_type::trigger_mode_type::INPUT);
- node.set_trigger_input_mask(0b1);
- if (i != 0) {
- test_type::connect(pool[i - 1], 0, node, 0);
- }
- co_await node.start();
- }
- auto test_data = test_type::data_packet::new_instance();
- test_data->refresh();
- for (auto _: state) {
- pool[0].update_input_data(0, test_data);
- assert(pool[total - 1].cnt == total);
- }
- }, detached);
- high_freq_context.run();
- }
- BENCHMARK(BM_datanode_chain)->RangeMultiplier(10)->Range(1, 1e6);
- BENCHMARK_MAIN();
|