#include "core/datanode_base.h" #include #include #include #include #include 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 { uint64_t cnt = 0; awaitable 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 { 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();