feat update
All checks were successful
linux-x64-gcc / linux-gcc (Debug) (push) Successful in 36s
linux-x64-gcc / linux-gcc (Release) (push) Successful in 41s

This commit is contained in:
tqcq 2024-03-10 22:26:33 +08:00
parent ab35717dc4
commit d85287d60a
5 changed files with 121 additions and 15 deletions

View File

@ -77,7 +77,11 @@ target_link_libraries(sled PUBLIC rpc_core fmt marl)
if(SLED_BUILD_BENCHMARK)
find_package(benchmark REQUIRED)
add_executable(sled_benchmark "src/system/fiber/fiber_bench.cc")
add_executable(sled_benchmark
src/random_bench.cc
src/strings/base64_bench.cc
src/system/fiber/fiber_bench.cc
)
target_link_libraries(sled_benchmark PRIVATE sled benchmark::benchmark
benchmark::benchmark_main)
endif(SLED_BUILD_BENCHMARK)

56
src/random_bench.cc Normal file
View File

@ -0,0 +1,56 @@
#include <benchmark/benchmark.h>
#include <sled/random.h>
class RandomFixture : public benchmark::Fixture {
void SetUp(::benchmark::State &state) { rand_ = new sled::Random(1314); }
void TearDown(::benchmark::State &state) { delete rand_; }
protected:
sled::Random *rand_;
};
BENCHMARK_F(RandomFixture, bool)(benchmark::State &state)
{
for (auto _ : state) { bool b = rand_->Rand<bool>(); }
}
BENCHMARK_F(RandomFixture, int32_t)(benchmark::State &state)
{
for (auto _ : state) { int32_t i = rand_->Rand<int8_t>(); }
}
BENCHMARK_F(RandomFixture, int32_t_range)(benchmark::State &state)
{
for (auto _ : state) { int32_t i = rand_->Rand(-1000, 1000); }
}
BENCHMARK_F(RandomFixture, uint32_t)(benchmark::State &state)
{
for (auto _ : state) { uint32_t i = rand_->Rand<uint32_t>(); }
}
BENCHMARK_F(RandomFixture, uint32_t_range)(benchmark::State &state)
{
for (auto _ : state) { uint32_t i = rand_->Rand(0u, 1000u); }
}
BENCHMARK_F(RandomFixture, Gaussian)(benchmark::State &state)
{
for (auto _ : state) { double d = rand_->Gaussian(0, 1); }
}
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>(); }
}

View File

@ -1,5 +1,5 @@
#include "sled/strings/base64.h"
#include <fmt/format.h>
#include <sled/strings/base64.h>
#include <sstream>
namespace sled {

View File

@ -0,0 +1,12 @@
#include <benchmark/benchmark.h>
#include <sled/random.h>
#include <sled/strings/base64.h>
static void
Base64Encode(benchmark::State &state)
{
std::string input = "hello world\n";
for (auto _ : state) { (void) sled::Base64::Encode(input); }
}
BENCHMARK(Base64Encode)->RangeMultiplier(10)->Range(10, 1000000);

View File

@ -2,24 +2,58 @@
#include <sled/system/fiber/scheduler.h>
#include <sled/system/fiber/wait_group.h>
static void
SingleQueue(benchmark::State &state)
{
for (auto _ : state) {
state.PauseTiming();
sled::Scheduler scheduler(
sled::Scheduler::Config().setWorkerThreadCount(0));
scheduler.bind();
defer(scheduler.unbind());
const int num_tasks = state.range(0);
sled::WaitGroup wg(num_tasks);
sled::WaitGroup start_flag(1);
for (int i = 0; i < num_tasks; i++) {
sled::Schedule([=] {
start_flag.Wait();
wg.Done();
});
}
state.ResumeTiming();
start_flag.Done();
wg.Wait();
state.PauseTiming();
}
}
static void
MultiQueue(benchmark::State &state)
{
sled::Scheduler scheduler(sled::Scheduler::Config::allCores());
scheduler.bind();
defer(scheduler.unbind());
const int num_tasks = state.range(0);
sled::WaitGroup wg(num_tasks);
sled::WaitGroup start_flag(1);
for (int i = 0; i < num_tasks; i++) {
sled::Schedule([=] {
start_flag.Wait();
wg.Done();
});
for (auto _ : state) {
state.PauseTiming();
sled::Scheduler scheduler(sled::Scheduler::Config::allCores());
scheduler.bind();
defer(scheduler.unbind());
const int num_tasks = state.range(0);
sled::WaitGroup wg(num_tasks);
sled::WaitGroup start_flag(1);
for (int i = 0; i < num_tasks; i++) {
sled::Schedule([=] {
start_flag.Wait();
wg.Done();
});
}
state.ResumeTiming();
start_flag.Done();
wg.Wait();
state.PauseTiming();
}
start_flag.Done();
wg.Wait();
}
BENCHMARK(MultiQueue)->RangeMultiplier(10)->Range(10, 10000);
BENCHMARK(SingleQueue)->RangeMultiplier(10)->Range(10, 10000);