fix pause_timer
This commit is contained in:
parent
8cdba6aad1
commit
78eedb6a65
@ -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`
|
||||
|
@ -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)
|
||||
|
@ -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
37
src/sled/uri_bench.cc
Normal 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);
|
Loading…
Reference in New Issue
Block a user