Skip to content

Commit 028adc3

Browse files
committed
Add time offset query benchmark
1 parent b66b9b7 commit 028adc3

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

testing/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ if(LSL_BENCHMARKS)
6060

6161
add_executable(lsl_bench_internal
6262
bench_int_sleep.cpp
63+
bench_int_timesync.cpp
6364
)
6465
target_link_libraries(lsl_bench_internal PRIVATE lslobj lslboost catch_main)
6566
target_include_directories(lsl_test_internal PRIVATE ${CMAKE_CURRENT_LIST_DIR}/../src/)

testing/bench_int_timesync.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include "stream_info_impl.h"
2+
#include "udp_server.h"
3+
#include <catch2/catch.hpp>
4+
#include <sstream>
5+
#include <thread>
6+
7+
using namespace lslboost::asio::ip;
8+
9+
TEST_CASE("timesync", "[basic][latency]") {
10+
auto info =
11+
std::make_shared<lsl::stream_info_impl>("Dummy", "dummy", 1, 1., cft_int8, "abcdef123");
12+
lslboost::asio::io_context ctx;
13+
auto udp_server = std::make_shared<lsl::udp_server>(info, ctx, lslboost::asio::ip::udp::v4());
14+
udp::endpoint ep(address_v4(0x7f000001), info->v4service_port());
15+
16+
INFO(info->to_shortinfo_message())
17+
udp_server->begin_serving();
18+
std::thread iothread([&ctx]() { ctx.run(); });
19+
20+
const char request[] = "LSL:timedata\n1 0.0";
21+
asio::basic_datagram_socket<asio::ip::udp, asio::io_context::executor_type> sock(ctx, udp::endpoint());
22+
char buf[500]={0};
23+
BENCHMARK("timedata") {
24+
sock.send_to(lslboost::asio::const_buffer(request, sizeof(request)-1), ep);
25+
REQUIRE(sock.receive(lslboost::asio::mutable_buffer(buf, 500)) > 0);
26+
};
27+
udp_server->end_serving();
28+
ctx.stop();
29+
iothread.join();
30+
}

0 commit comments

Comments
 (0)