Squashed 'libs/CommService/' content from commit 7ccc0fc

git-subtree-dir: libs/CommService
git-subtree-split: 7ccc0fce88bbc5969df060058cf0fb57abe3bcf9
This commit is contained in:
Henry Winkel
2022-09-15 09:53:53 +02:00
commit cc67e4840f
799 changed files with 179487 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
cmake_minimum_required(VERSION 2.8)
project(loguru_bench)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif(NOT CMAKE_BUILD_TYPE)
MESSAGE(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Werror -Wall -Wextra")
file(GLOB source
"${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
)
add_executable(loguru_bench ${source})
find_package(Threads)
target_link_libraries(loguru_bench ${CMAKE_THREAD_LIBS_INIT}) # For pthreads
target_link_libraries(loguru_bench dl) # For ldl

View File

@@ -0,0 +1,12 @@
#!/bin/bash
set -e # Fail on error
ROOT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
cd "$ROOT_DIR"
mkdir -p build
cd build
cmake ..
make
./loguru_bench $@ 2>/dev/null

View File

@@ -0,0 +1,121 @@
#include <chrono>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
#define LOGURU_WITH_STREAMS 1
#define LOGURU_REDEFINE_ASSERT 1
#include "../loguru.cpp"
const size_t kNumRuns = 10;
const double kPi = 3.1415926535897932384626433;
static long long now_ns()
{
using namespace std::chrono;
return duration_cast<nanoseconds>(high_resolution_clock::now().time_since_epoch()).count();
}
template<typename Function>
void bench(const std::string& name, const Function& function, size_t num_iterations)
{
function(num_iterations); // Warm-up.
printf("%-30s ", name.c_str());
fflush(stdout);
std::vector<double> times;
double sum = 0;
for (size_t i = 0; i < kNumRuns; ++i) {
auto start_ns = now_ns();
function(num_iterations);
double total_time_sec = (now_ns() - start_ns) * 1e-9;
times.push_back(total_time_sec / num_iterations);
sum += times.back();
}
double mean = sum / kNumRuns;
double std_dev_sum = 0;
for (double time : times) {
std_dev_sum += (time - mean) * (time - mean);
}
double variance = std::sqrt(std_dev_sum / kNumRuns);
printf("%6.3f ± %.3f μs per call\n", mean * 1e6, variance * 1e6);
fflush(stdout);
}
// ----------------------------------------------------------------------------
void format_strings(size_t num_iterations)
{
for (size_t i = 0; i < num_iterations; ++i) {
LOG_F(WARNING, "Some long, complex message.");
}
loguru::flush();
}
void format_float(size_t num_iterations)
{
for (size_t i = 0; i < num_iterations; ++i) {
LOG_F(WARNING, "%+05.3f", kPi);
}
loguru::flush();
}
void stream_strings(size_t num_iterations)
{
for (size_t i = 0; i < num_iterations; ++i) {
LOG_S(WARNING) << "Some long, complex message.";
}
loguru::flush();
}
void stream_float(size_t num_iterations)
{
for (size_t i = 0; i < num_iterations; ++i) {
LOG_S(WARNING) << std::setfill('0') << std::setw(5) << std::setprecision(3) << kPi;
}
loguru::flush();
}
void raw_string_float(size_t num_iterations)
{
for (size_t i = 0; i < num_iterations; ++i) {
RAW_LOG_F(WARNING, "Some long, complex message.");
}
loguru::flush();
}
void error_context(size_t num_iterations)
{
for (size_t i = 0; i < num_iterations; ++i) {
ERROR_CONTEXT("key", "value");
}
}
int main(int argc, char* argv[])
{
const size_t kNumIterations = 50 * 1000;
loguru::init(argc, argv);
loguru::add_file("loguru_bench.log", loguru::Truncate, loguru::Verbosity_INFO);
bench("ERROR_CONTEXT", error_context, kNumIterations * 100);
loguru::g_flush_interval_ms = 200;
bench("LOG_F string (buffered):", format_strings, kNumIterations);
bench("LOG_F float (buffered):", format_float, kNumIterations);
bench("LOG_S string (buffered):", stream_strings, kNumIterations);
bench("LOG_S float (buffered):", stream_float, kNumIterations);
bench("RAW_LOG_F (buffered):", raw_string_float, kNumIterations);
loguru::g_flush_interval_ms = 0;
bench("LOG_F string (unbuffered):", format_strings, kNumIterations);
bench("LOG_F float (unbuffered):", format_float, kNumIterations);
bench("LOG_S string (unbuffered):", stream_strings, kNumIterations);
bench("LOG_S float (unbuffered):", stream_float, kNumIterations);
bench("RAW_LOG_F (unbuffered):", raw_string_float, kNumIterations);
}