diff --git a/.gitea/workflows/linux-x64-gcc.yml b/.gitea/workflows/linux-x64-gcc.yml index be4d119..bbecaf8 100644 --- a/.gitea/workflows/linux-x64-gcc.yml +++ b/.gitea/workflows/linux-x64-gcc.yml @@ -40,7 +40,7 @@ jobs: - name: configure run: | mkdir build && cd build - cmake .. -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DSLED_BUILD_TESTS=ON -DSLED_BUILD_BENCHMARK=ON + cmake .. -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DSLED_BUILD_BENCHMARK=ON -DSLED_BUILD_TESTS=ON - name: build run: | cmake --build build -j `nproc` diff --git a/CMakeLists.txt b/CMakeLists.txt index 01e1356..a6a4f17 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -117,7 +117,8 @@ if(SLED_BUILD_BENCHMARK) # src/sled/system/fiber/fiber_bench.cc src/sled/system/thread_bench.cc src/sled/system/thread_pool_bench.cc - src/sled/system_time_bench.cc) + src/sled/system_time_bench.cc + src/sled/uri_bench.cc) target_link_libraries(sled_benchmark PRIVATE sled benchmark_main) target_compile_options(sled_benchmark PRIVATE -include sled/testing/benchmark.h) @@ -152,6 +153,7 @@ function(sled_add_test) endfunction() if(SLED_BUILD_TESTS) + enable_testing() # include(FetchContent) FetchContent_Declare( googletest URL # https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip # ) FetchContent_MakeAvailable(googletest) diff --git a/src/sled/testing/picobench.h b/src/sled/testing/picobench.h index 17e933c..ec53c01 100644 --- a/src/sled/testing/picobench.h +++ b/src/sled/testing/picobench.h @@ -211,8 +211,10 @@ public: PICOBENCH_INLINE void pause_timer() { - auto duration = high_res_clock::now() - _start; - _duration_ns += std::chrono::duration_cast(duration).count(); + if (!_pause) { + auto duration = high_res_clock::now() - _start; + _duration_ns += std::chrono::duration_cast(duration).count(); + } _pause = true; } diff --git a/src/sled/uri_bench.cc b/src/sled/uri_bench.cc new file mode 100644 index 0000000..dd15ebf --- /dev/null +++ b/src/sled/uri_bench.cc @@ -0,0 +1,37 @@ +#include +#include + +std::string +GenerateURI(int length) +{ + std::string uri = "http://host"; + // add host + for (int i = 0; i < length; i++) { uri.append("host"); } + for (int i = 0; i < length; i++) { uri.append("/path"); } + if (length > 0) { uri.append("?"); } + for (int i = 0; i < length; i++) { + if (i) { uri.append("&"); } + uri.append("key" + std::to_string(i) + "=value"); + } + + uri.append("#fragment"); + + return uri; +} + +void +ParseURI(picobench::state &s) +{ + // int length = 0; + for (auto _ : s) { + s.pause_timer(); + auto uri_str = GenerateURI(10); + s.resume_timer(); + auto uri_or = sled::URI::ParseURI(uri_str); + s.pause_timer(); + SLED_ASSERT(uri_or.ok() == true, ""); + SLED_ASSERT(uri_or.value().href() == uri_str, "{} != {}", uri_or.value().href(), uri_str); + } +} + +PICOBENCH(ParseURI);