diff --git a/.gitmodules b/.gitmodules index f3c5479..c8edf6a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,3 @@ [submodule "fmt"] path = fmt url = https://github.com/fmtlib/fmt -[submodule "bench/Nanolog"] - path = bench/Nanolog - url = https://github.com/PlatformLab/NanoLog -[submodule "bench/spdlog"] - path = bench/spdlog - url = https://github.com/gabime/spdlog diff --git a/CMakeLists.txt b/CMakeLists.txt index be19fac..aa64a8a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,3 @@ install(TARGETS fmtlog-static) add_subdirectory(fmt) add_subdirectory(test) -if(NOT MSVC) - add_subdirectory(bench) -endif() diff --git a/bench/CMakeLists.txt b/bench/CMakeLists.txt deleted file mode 100644 index db00175..0000000 --- a/bench/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -add_library(NanoLog NanoLog/runtime/Cycles.cc NanoLog/runtime/Util.cc NanoLog/runtime/Log.cc NanoLog/runtime/NanoLog.cc NanoLog/runtime/RuntimeLogger.cc NanoLog/runtime/TimeTrace.cc) - -add_executable(bench bench.cc) -target_include_directories(bench PRIVATE spdlog/include) -target_compile_options(bench PRIVATE -Wno-unused-function) -target_link_libraries(bench fmtlog-static fmt NanoLog rt) -install(TARGETS bench) diff --git a/bench/NanoLog b/bench/NanoLog deleted file mode 160000 index 2a94d70..0000000 --- a/bench/NanoLog +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 2a94d70f9d1db4da416053b1b926387fa068a59b diff --git a/bench/bench.cc b/bench/bench.cc deleted file mode 100644 index c5895b1..0000000 --- a/bench/bench.cc +++ /dev/null @@ -1,212 +0,0 @@ -#include -#include - -#include "../fmtlog.h" -#include "spdlog/spdlog.h" -#include "spdlog/sinks/basic_file_sink.h" -#include "spdlog/async.h" -#include "NanoLog/runtime/NanoLogCpp17.h" - -namespace GeneratedFunctions { -size_t numLogIds; -}; - -struct FmtLogBase -{ - void flush() { fmtlog::poll(true); } -}; - -struct StaticString : public FmtLogBase -{ - inline void log() { logi("Starting backup replica garbage collector thread"); } -}; - -struct StringConcat : public FmtLogBase -{ - inline void log() { logi("Opened session with coordinator at {}", "basic+udp:host=192.168.1.140,port=12246"); } -}; - -struct SingleInteger : public FmtLogBase -{ - inline void log() { logi("Backup storage speeds (min): {} MB/s read", 181); } -}; - -struct TwoIntegers : public FmtLogBase -{ - inline void log() { - logi("buffer has consumed {} bytes of extra storage, current allocation: {} bytes", 1032024, 1016544); - } -}; - -struct SingleDouble : public FmtLogBase -{ - inline void log() { logi("Using tombstone ratio balancer with ratio = {}", 0.400000); } -}; - -struct ComplexFormat : public FmtLogBase -{ - inline void log() { - logi("Initialized InfUdDriver buffers: {} receive buffers ({} MB), {} transmit buffers ({} MB), took {:.1f} ms", - 50000, 97, 50, 0, 26.2); - } -}; - -struct NanoLogBase -{ - void flush() { NanoLog::sync(); } -}; - -struct NanoLogStaticString : public NanoLogBase -{ - inline void log() { NANO_LOG(NOTICE, "Starting backup replica garbage collector thread"); } -}; - -struct NanoLogStringConcat : public NanoLogBase -{ - inline void log() { - NANO_LOG(NOTICE, "Opened session with coordinator at %s", "basic+udp:host=192.168.1.140,port=12246"); - } -}; - -struct NanoLogSingleInteger : public NanoLogBase -{ - inline void log() { NANO_LOG(NOTICE, "Backup storage speeds (min): %d MB/s read", 181); } -}; - -struct NanoLogTwoIntegers : public NanoLogBase -{ - inline void log() { - NANO_LOG(NOTICE, "buffer has consumed %u bytes of extra storage, current allocation: %u bytes", 1032024, 1016544); - } -}; - -struct NanoLogSingleDouble : public NanoLogBase -{ - inline void log() { NANO_LOG(NOTICE, "Using tombstone ratio balancer with ratio = %0.6lf", 0.400000); } -}; - -struct NanoLogComplexFormat : public NanoLogBase -{ - inline void log() { - NANO_LOG(NOTICE, - "Initialized InfUdDriver buffers: %u receive buffers (%u MB), %u transmit buffers (%u MB), took %0.1lf ms", - 50000, 97, 50, 0, 26.2); - } -}; - -struct SpdlogBase -{ - SpdlogBase(spdlog::logger* logger) - : logger(logger) {} - - void flush() { logger->flush(); } - - spdlog::logger* logger; -}; - -struct SpdlogStaticString : public SpdlogBase -{ - SpdlogStaticString(spdlog::logger* logger) - : SpdlogBase(logger) {} - inline void log() { SPDLOG_LOGGER_INFO(logger, "Starting backup replica garbage collector thread"); } -}; - -struct SpdlogStringConcat : public SpdlogBase -{ - SpdlogStringConcat(spdlog::logger* logger) - : SpdlogBase(logger) {} - inline void log() { - SPDLOG_LOGGER_INFO(logger, "Opened session with coordinator at {}", "basic+udp:host=192.168.1.140,port=12246"); - } -}; - -struct SpdlogSingleInteger : public SpdlogBase -{ - SpdlogSingleInteger(spdlog::logger* logger) - : SpdlogBase(logger) {} - inline void log() { SPDLOG_LOGGER_INFO(logger, "Backup storage speeds (min): {} MB/s read", 181); } -}; - -struct SpdlogTwoIntegers : public SpdlogBase -{ - SpdlogTwoIntegers(spdlog::logger* logger) - : SpdlogBase(logger) {} - inline void log() { - SPDLOG_LOGGER_INFO(logger, "buffer has consumed {} bytes of extra storage, current allocation: {} bytes", 1032024, - 1016544); - } -}; - -struct SpdlogSingleDouble : public SpdlogBase -{ - SpdlogSingleDouble(spdlog::logger* logger) - : SpdlogBase(logger) {} - inline void log() { SPDLOG_LOGGER_INFO(logger, "Using tombstone ratio balancer with ratio = {}", 0.400000); } -}; - -struct SpdlogComplexFormat : public SpdlogBase -{ - SpdlogComplexFormat(spdlog::logger* logger) - : SpdlogBase(logger) {} - inline void log() { - SPDLOG_LOGGER_INFO( - logger, - "Initialized InfUdDriver buffers: {} receive buffers ({} MB), {} transmit buffers ({} MB), took {:.1f} ms", 50000, - 97, 50, 0, 26.2); - } -}; - -template -void bench(T o) { - const int RECORDS = 10000; - std::chrono::high_resolution_clock::time_point t0, t1, t2; - t0 = std::chrono::high_resolution_clock::now(); - for (int i = 0; i < RECORDS; ++i) { - o.log(); - } - t1 = std::chrono::high_resolution_clock::now(); - o.flush(); - t2 = std::chrono::high_resolution_clock::now(); - double span1 = std::chrono::duration_cast>(t1 - t0).count(); - double span2 = std::chrono::duration_cast>(t2 - t0).count(); - fmt::print("{}: front-end latency is {:.1f} ns/msg average, throughput is {:.2f} million msgs/sec average\n", - typeid(o).name(), (span1 / RECORDS) * 1e9, RECORDS / span2 / 1e6); -} - -int main() { - fmtlog::setLogFile("fmtlog.txt", true); - fmtlog::setHeaderPattern("[{YmdHMSe}] [fmtlog] [{l}] [{s}] "); - fmtlog::preallocate(); - - NanoLog::setLogFile("nanalog.bin"); - NanoLog::preallocate(); - - auto spdlogger = spdlog::basic_logger_st("spdlog", "spdlog.txt", true); - - bench(StaticString()); - bench(StringConcat()); - bench(SingleInteger()); - bench(TwoIntegers()); - bench(SingleDouble()); - bench(ComplexFormat()); - - fmt::print("\n"); - - bench(NanoLogStaticString()); - bench(NanoLogStringConcat()); - bench(NanoLogSingleInteger()); - bench(NanoLogTwoIntegers()); - bench(NanoLogSingleDouble()); - bench(NanoLogComplexFormat()); - - fmt::print("\n"); - - bench(SpdlogStaticString(spdlogger.get())); - bench(SpdlogStringConcat(spdlogger.get())); - bench(SpdlogSingleInteger(spdlogger.get())); - bench(SpdlogTwoIntegers(spdlogger.get())); - bench(SpdlogSingleDouble(spdlogger.get())); - bench(SpdlogComplexFormat(spdlogger.get())); - - return 0; -} diff --git a/bench/spdlog b/bench/spdlog deleted file mode 160000 index 81de01c..0000000 --- a/bench/spdlog +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 81de01c02c2b49aa723806b0c1d557dd05721635