fix pause_timer
This commit is contained in:
parent
8cdba6aad1
commit
78eedb6a65
@ -40,7 +40,7 @@ jobs:
|
|||||||
- name: configure
|
- name: configure
|
||||||
run: |
|
run: |
|
||||||
mkdir build && cd build
|
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
|
- name: build
|
||||||
run: |
|
run: |
|
||||||
cmake --build build -j `nproc`
|
cmake --build build -j `nproc`
|
||||||
|
@ -117,7 +117,8 @@ if(SLED_BUILD_BENCHMARK)
|
|||||||
# src/sled/system/fiber/fiber_bench.cc
|
# src/sled/system/fiber/fiber_bench.cc
|
||||||
src/sled/system/thread_bench.cc
|
src/sled/system/thread_bench.cc
|
||||||
src/sled/system/thread_pool_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_link_libraries(sled_benchmark PRIVATE sled benchmark_main)
|
||||||
target_compile_options(sled_benchmark PRIVATE -include
|
target_compile_options(sled_benchmark PRIVATE -include
|
||||||
sled/testing/benchmark.h)
|
sled/testing/benchmark.h)
|
||||||
@ -152,6 +153,7 @@ function(sled_add_test)
|
|||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
if(SLED_BUILD_TESTS)
|
if(SLED_BUILD_TESTS)
|
||||||
|
enable_testing()
|
||||||
# include(FetchContent) FetchContent_Declare( googletest URL
|
# include(FetchContent) FetchContent_Declare( googletest URL
|
||||||
# https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
|
# https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
|
||||||
# ) FetchContent_MakeAvailable(googletest)
|
# ) FetchContent_MakeAvailable(googletest)
|
||||||
|
@ -211,8 +211,10 @@ public:
|
|||||||
PICOBENCH_INLINE
|
PICOBENCH_INLINE
|
||||||
void pause_timer()
|
void pause_timer()
|
||||||
{
|
{
|
||||||
auto duration = high_res_clock::now() - _start;
|
if (!_pause) {
|
||||||
_duration_ns += std::chrono::duration_cast<std::chrono::nanoseconds>(duration).count();
|
auto duration = high_res_clock::now() - _start;
|
||||||
|
_duration_ns += std::chrono::duration_cast<std::chrono::nanoseconds>(duration).count();
|
||||||
|
}
|
||||||
_pause = true;
|
_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…
x
Reference in New Issue
Block a user