feat update picobench
This commit is contained in:
parent
7c1582769e
commit
34897eeb40
@ -18,6 +18,10 @@ set(BUILD_RTTR_DYNAMIC OFF)
|
|||||||
set(BUILD_UNIT_TESTS OFF)
|
set(BUILD_UNIT_TESTS OFF)
|
||||||
set(BUILD_EXAMPLES OFF)
|
set(BUILD_EXAMPLES OFF)
|
||||||
add_library(test_main STATIC src/sled/testing/test_main.cc)
|
add_library(test_main STATIC src/sled/testing/test_main.cc)
|
||||||
|
add_library(benchmark_main STATIC src/sled/testing/benchmark_main.cc)
|
||||||
|
target_include_directories(test_main PUBLIC src/)
|
||||||
|
target_include_directories(benchmark_main PUBLIC src/)
|
||||||
|
|
||||||
add_library(sled STATIC "")
|
add_library(sled STATIC "")
|
||||||
|
|
||||||
add_subdirectory(3party/gperftools EXCLUDE_FROM_ALL)
|
add_subdirectory(3party/gperftools EXCLUDE_FROM_ALL)
|
||||||
@ -43,7 +47,6 @@ endif()
|
|||||||
# add_subdirectory(3party/eigen EXCLUDE_FROM_ALL)
|
# add_subdirectory(3party/eigen EXCLUDE_FROM_ALL)
|
||||||
target_include_directories(sled PUBLIC src/ 3party/eigen 3party/inja
|
target_include_directories(sled PUBLIC src/ 3party/eigen 3party/inja
|
||||||
3party/rxcpp)
|
3party/rxcpp)
|
||||||
target_include_directories(test_main PUBLIC src/)
|
|
||||||
target_sources(
|
target_sources(
|
||||||
sled
|
sled
|
||||||
PRIVATE src/sled/async/async.cc
|
PRIVATE src/sled/async/async.cc
|
||||||
@ -71,6 +74,7 @@ target_sources(
|
|||||||
src/sled/task_queue/pending_task_safety_flag.cc
|
src/sled/task_queue/pending_task_safety_flag.cc
|
||||||
src/sled/task_queue/task_queue_base.cc
|
src/sled/task_queue/task_queue_base.cc
|
||||||
src/sled/testing/test.cc
|
src/sled/testing/test.cc
|
||||||
|
src/sled/testing/benchmark.cc
|
||||||
src/sled/timer/task_queue_timeout.cc
|
src/sled/timer/task_queue_timeout.cc
|
||||||
src/sled/timer/timer.cc
|
src/sled/timer/timer.cc
|
||||||
src/sled/units/time_delta.cc
|
src/sled/units/time_delta.cc
|
||||||
@ -104,17 +108,19 @@ target_link_libraries(
|
|||||||
set_target_properties(sled PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
set_target_properties(sled PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||||
|
|
||||||
if(SLED_BUILD_BENCHMARK)
|
if(SLED_BUILD_BENCHMARK)
|
||||||
if(NOT TARGET benchmark)
|
# if(NOT TARGET benchmark) find_package(mbenchmark REQUIRED) endif()
|
||||||
find_package(benchmark REQUIRED)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
add_executable(
|
add_executable(
|
||||||
sled_benchmark
|
sled_benchmark
|
||||||
src/sled/random_bench.cc src/sled/strings/base64_bench.cc
|
src/sled/random_bench.cc
|
||||||
src/sled/system/fiber/fiber_bench.cc src/sled/system/thread_pool_bench.cc
|
src/sled/strings/base64_bench.cc
|
||||||
|
# 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)
|
||||||
target_link_libraries(sled_benchmark PRIVATE sled benchmark::benchmark
|
target_link_libraries(sled_benchmark PRIVATE sled benchmark_main)
|
||||||
benchmark::benchmark_main)
|
target_compile_options(sled_benchmark PRIVATE -include
|
||||||
|
sled/testing/benchmark.h)
|
||||||
endif(SLED_BUILD_BENCHMARK)
|
endif(SLED_BUILD_BENCHMARK)
|
||||||
|
|
||||||
function(sled_add_test)
|
function(sled_add_test)
|
||||||
|
22
README.md
22
README.md
@ -3,3 +3,25 @@
|
|||||||
- [ ] add log module
|
- [ ] add log module
|
||||||
- [ ] add http module(cpp-httplib)
|
- [ ] add http module(cpp-httplib)
|
||||||
- [ ] add ORM module
|
- [ ] add ORM module
|
||||||
|
|
||||||
|
|
||||||
|
## Benchmark
|
||||||
|
Name (* = baseline) | ns/op | Baseline | Ops/second
|
||||||
|
--------------------------|--------:|---------:|-----------:
|
||||||
|
Random bool * | 9 | - | 109123586.4
|
||||||
|
Random int8_t | 7 | 0.778 | 134375880.8
|
||||||
|
Random int32_t | 8 | 0.889 | 120300189.7
|
||||||
|
Random uint32_t | 7 | 0.778 | 131234452.1
|
||||||
|
Random uint32_t range | 8 | 0.889 | 123079276.7
|
||||||
|
Gaussian(0, 1) | 17 | 1.889 | 58742994.8
|
||||||
|
Exponential(1) | 12 | 1.333 | 81447219.4
|
||||||
|
Random float | 7 | 0.778 | 136571495.3
|
||||||
|
Random double | 7 | 0.778 | 131796121.5
|
||||||
|
Base64Encode | 106299 |11811.000 | 9407.4
|
||||||
|
Base64Decode | 104897 |11655.222 | 9533.1
|
||||||
|
ThreadBlockingCallByDefaultSocketServer | 6624 | 736.000 | 150950.1
|
||||||
|
ThreadBlockingCallByNullSocketServer | 5309 | 589.889 | 188358.8
|
||||||
|
ThreadPoolBench | 3096 | 344.000 | 322941.4
|
||||||
|
SystemTimeNanos | 24 | 2.667 | 40659163.6
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,56 +1,47 @@
|
|||||||
#include <benchmark/benchmark.h>
|
|
||||||
#include <sled/random.h>
|
#include <sled/random.h>
|
||||||
|
#include <sled/testing/benchmark.h>
|
||||||
|
|
||||||
class RandomFixture : public benchmark::Fixture {
|
PICOBENCH([](picobench::state &s) {
|
||||||
void SetUp(::benchmark::State &state) { rand_ = new sled::Random(1314); }
|
sled::Random rand(s.user_data());
|
||||||
|
for (auto _ : s) { bool b = rand.Rand<bool>(); }
|
||||||
|
}).label("Random bool");
|
||||||
|
|
||||||
void TearDown(::benchmark::State &state) { delete rand_; }
|
PICOBENCH([](picobench::state &s) {
|
||||||
|
sled::Random rand(s.user_data());
|
||||||
|
for (auto _ : s) { int32_t i = rand.Rand<int8_t>(); }
|
||||||
|
}).label("Random int8_t");
|
||||||
|
|
||||||
protected:
|
PICOBENCH([](picobench::state &s) {
|
||||||
sled::Random *rand_;
|
sled::Random rand(s.user_data());
|
||||||
};
|
for (auto _ : s) { int32_t i = rand.Rand(-1000, 1000); }
|
||||||
|
}).label("Random int32_t");
|
||||||
|
|
||||||
BENCHMARK_F(RandomFixture, bool)(benchmark::State &state)
|
PICOBENCH([](picobench::state &s) {
|
||||||
{
|
sled::Random rand(s.user_data());
|
||||||
for (auto _ : state) { bool b = rand_->Rand<bool>(); }
|
for (auto _ : s) { uint32_t i = rand.Rand<uint32_t>(); }
|
||||||
}
|
}).label("Random uint32_t");
|
||||||
|
|
||||||
BENCHMARK_F(RandomFixture, int32_t)(benchmark::State &state)
|
PICOBENCH([](picobench::state &s) {
|
||||||
{
|
sled::Random rand(s.user_data());
|
||||||
for (auto _ : state) { int32_t i = rand_->Rand<int8_t>(); }
|
for (auto _ : s) { uint32_t i = rand.Rand(0u, 1000u); }
|
||||||
}
|
}).label("Random uint32_t range");
|
||||||
|
|
||||||
BENCHMARK_F(RandomFixture, int32_t_range)(benchmark::State &state)
|
PICOBENCH([](picobench::state &s) {
|
||||||
{
|
sled::Random rand(s.user_data());
|
||||||
for (auto _ : state) { int32_t i = rand_->Rand(-1000, 1000); }
|
for (auto _ : s) { double d = rand.Gaussian(0, 1); }
|
||||||
}
|
}).label("Gaussian(0, 1)");
|
||||||
|
|
||||||
BENCHMARK_F(RandomFixture, uint32_t)(benchmark::State &state)
|
PICOBENCH([](picobench::state &s) {
|
||||||
{
|
sled::Random rand(s.user_data());
|
||||||
for (auto _ : state) { uint32_t i = rand_->Rand<uint32_t>(); }
|
for (auto _ : s) { double d = rand.Exponential(1); }
|
||||||
}
|
}).label("Exponential(1)");
|
||||||
|
|
||||||
BENCHMARK_F(RandomFixture, uint32_t_range)(benchmark::State &state)
|
PICOBENCH([](picobench::state &s) {
|
||||||
{
|
sled::Random rand(s.user_data());
|
||||||
for (auto _ : state) { uint32_t i = rand_->Rand(0u, 1000u); }
|
for (auto _ : s) { float f = rand.Rand<float>(); }
|
||||||
}
|
}).label("Random float");
|
||||||
|
|
||||||
BENCHMARK_F(RandomFixture, Gaussian)(benchmark::State &state)
|
PICOBENCH([](picobench::state &s) {
|
||||||
{
|
sled::Random rand(s.user_data());
|
||||||
for (auto _ : state) { double d = rand_->Gaussian(0, 1); }
|
for (auto _ : s) { double d = rand.Rand<double>(); }
|
||||||
}
|
}).label("Random double");
|
||||||
|
|
||||||
BENCHMARK_F(RandomFixture, Exponential)(benchmark::State &state)
|
|
||||||
{
|
|
||||||
for (auto _ : state) { double d = rand_->Exponential(1); }
|
|
||||||
}
|
|
||||||
|
|
||||||
BENCHMARK_F(RandomFixture, float)(benchmark::State &state)
|
|
||||||
{
|
|
||||||
for (auto _ : state) { float f = rand_->Rand<float>(); }
|
|
||||||
}
|
|
||||||
|
|
||||||
BENCHMARK_F(RandomFixture, double)(benchmark::State &state)
|
|
||||||
{
|
|
||||||
for (auto _ : state) { double d = rand_->Rand<double>(); }
|
|
||||||
}
|
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
#include <benchmark/benchmark.h>
|
|
||||||
#include <sled/random.h>
|
#include <sled/random.h>
|
||||||
#include <sled/strings/base64.h>
|
#include <sled/strings/base64.h>
|
||||||
|
#include <sled/testing/benchmark.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
static std::string
|
static std::string
|
||||||
RandomString(size_t length)
|
RandomString(size_t length)
|
||||||
{
|
{
|
||||||
static const char chars[] = "0123456789"
|
static const char chars[]
|
||||||
|
= "0123456789"
|
||||||
"abcdefghijklmnopqrstuvwxyz"
|
"abcdefghijklmnopqrstuvwxyz"
|
||||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
@ -16,27 +17,27 @@ RandomString(size_t length)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
Base64Encode(benchmark::State &state)
|
Base64Encode(picobench::state &state)
|
||||||
{
|
{
|
||||||
for (auto _ : state) {
|
for (auto _ : state) {
|
||||||
state.PauseTiming();
|
state.pause_timer();
|
||||||
std::string input = RandomString(state.range(0));
|
std::string input = RandomString(10000);
|
||||||
state.ResumeTiming();
|
state.resume_timer();
|
||||||
(void) sled::Base64::Encode(input);
|
(void) sled::Base64::Encode(input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
Base64Decode(benchmark::State &state)
|
Base64Decode(picobench::state &state)
|
||||||
{
|
{
|
||||||
for (auto _ : state) {
|
for (auto _ : state) {
|
||||||
state.PauseTiming();
|
state.pause_timer();
|
||||||
std::string input = RandomString(state.range(0));
|
std::string input = RandomString(10000);
|
||||||
std::string base64_input = sled::Base64::Encode(input);
|
std::string base64_input = sled::Base64::Encode(input);
|
||||||
state.ResumeTiming();
|
state.resume_timer();
|
||||||
(void) sled::Base64::Decode(base64_input);
|
(void) sled::Base64::Decode(base64_input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BENCHMARK(Base64Encode)->RangeMultiplier(100)->Range(10, 100000);
|
PICOBENCH(Base64Encode);
|
||||||
BENCHMARK(Base64Decode)->RangeMultiplier(100)->Range(10, 100000);
|
PICOBENCH(Base64Decode);
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
#include <benchmark/benchmark.h>
|
|
||||||
#include <sled/system/fiber/scheduler.h>
|
#include <sled/system/fiber/scheduler.h>
|
||||||
#include <sled/system/fiber/wait_group.h>
|
#include <sled/system/fiber/wait_group.h>
|
||||||
|
|
||||||
|
24
src/sled/system/thread_bench.cc
Normal file
24
src/sled/system/thread_bench.cc
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#include <sled/system/thread.h>
|
||||||
|
|
||||||
|
void
|
||||||
|
ThreadBlockingCallByDefaultSocketServer(picobench::state &s)
|
||||||
|
{
|
||||||
|
auto thread = sled::Thread::CreateWithSocketServer();
|
||||||
|
thread->Start();
|
||||||
|
for (auto _ : s) {
|
||||||
|
(void) thread->BlockingCall([] { return 1; });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ThreadBlockingCallByNullSocketServer(picobench::state &s)
|
||||||
|
{
|
||||||
|
auto thread = sled::Thread::Create();
|
||||||
|
thread->Start();
|
||||||
|
for (auto _ : s) {
|
||||||
|
(void) thread->BlockingCall([] { return 1; });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PICOBENCH(ThreadBlockingCallByDefaultSocketServer);
|
||||||
|
PICOBENCH(ThreadBlockingCallByNullSocketServer);
|
@ -1,20 +1,16 @@
|
|||||||
#include "sled/system/fiber/wait_group.h"
|
#include <sled/system/fiber/wait_group.h>
|
||||||
#include <benchmark/benchmark.h>
|
|
||||||
#include <future>
|
|
||||||
#include <sled/system/thread_pool.h>
|
#include <sled/system/thread_pool.h>
|
||||||
|
#include <sled/testing/benchmark.h>
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ThreadPoolBench(benchmark::State &state)
|
ThreadPoolBench(picobench::state &state)
|
||||||
{
|
{
|
||||||
sled::ThreadPool pool(-1);
|
sled::ThreadPool pool(-1);
|
||||||
for (auto _ : state) {
|
for (auto _ : state) {
|
||||||
std::vector<std::future<int>> futures;
|
|
||||||
for (int i = 0; i < state.range(0); i++) {
|
|
||||||
std::future<int> f = pool.submit([]() { return 1; });
|
std::future<int> f = pool.submit([]() { return 1; });
|
||||||
futures.push_back(std::move(f));
|
(void) f.get();
|
||||||
}
|
|
||||||
for (auto &f : futures) { f.get(); }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BENCHMARK(ThreadPoolBench)->RangeMultiplier(10)->Range(10, 10000);
|
// BENCHMARK(ThreadPoolBench)->RangeMultiplier(10)->Range(10, 10000);
|
||||||
|
PICOBENCH(ThreadPoolBench);
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
#include <benchmark/benchmark.h>
|
|
||||||
#include <sled/system_time.h>
|
#include <sled/system_time.h>
|
||||||
|
#include <sled/testing/benchmark.h>
|
||||||
|
|
||||||
static void
|
static void
|
||||||
SystemTimeNanos(benchmark::State &state)
|
SystemTimeNanos(picobench::state &state)
|
||||||
{
|
{
|
||||||
for (auto _ : state) { (void) sled::SystemTimeNanos(); }
|
for (auto _ : state) { (void) sled::SystemTimeNanos(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
BENCHMARK(SystemTimeNanos);
|
PICOBENCH(SystemTimeNanos);
|
||||||
|
3
src/sled/testing/benchmark.cc
Normal file
3
src/sled/testing/benchmark.cc
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#define SLED_TESTING_BENCHMARK_H
|
||||||
|
// #define DOCTEST_CONFIG_IMPLEMENT
|
||||||
|
// #include "sled/testing/benchmark.h"
|
6
src/sled/testing/benchmark.h
Normal file
6
src/sled/testing/benchmark.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef SLED_TESTING_BENCHAMRK_H
|
||||||
|
#define SLED_TESTING_BENCHAMRK_H
|
||||||
|
|
||||||
|
#include "sled/testing/picobench.h"
|
||||||
|
|
||||||
|
#endif// SLED_TESTING_BENCHAMRK_H
|
11
src/sled/testing/benchmark_main.cc
Normal file
11
src/sled/testing/benchmark_main.cc
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#define SLED_TESTING_BENCHMARK_H
|
||||||
|
#define PICOBENCH_IMPLEMENT_WITH_MAIN
|
||||||
|
#include "sled/testing/benchmark.h"
|
||||||
|
|
||||||
|
// int
|
||||||
|
// main(int argc, char *argv[])
|
||||||
|
// {
|
||||||
|
// PICOBENCH_NAMESPACE::runner r;
|
||||||
|
// r.parse_cmd_line(argc, argv);
|
||||||
|
// return r.run();
|
||||||
|
// }
|
1393
src/sled/testing/picobench.h
Normal file
1393
src/sled/testing/picobench.h
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user