fix pause_timer
Some checks failed
linux-mips64-gcc / linux-gcc-mips64el (push) Failing after 1m55s
linux-x64-gcc / linux-gcc (Debug) (push) Failing after 1m5s
linux-x64-gcc / linux-gcc (Release) (push) Failing after 1m40s

This commit is contained in:
tqcq 2024-03-31 15:22:51 +08:00
parent 8cdba6aad1
commit 78eedb6a65
4 changed files with 45 additions and 4 deletions

View File

@ -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`

View File

@ -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)

View File

@ -211,8 +211,10 @@ public:
PICOBENCH_INLINE
void pause_timer()
{
auto duration = high_res_clock::now() - _start;
_duration_ns += std::chrono::duration_cast<std::chrono::nanoseconds>(duration).count();
if (!_pause) {
auto duration = high_res_clock::now() - _start;
_duration_ns += std::chrono::duration_cast<std::chrono::nanoseconds>(duration).count();
}
_pause = true;
}

37
src/sled/uri_bench.cc Normal file
View File

@ -0,0 +1,37 @@
#include <sled/log/log.h>
#include <sled/uri.h>
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);