From 6514736262f06156ddc63997be7c426964ddbd39 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Wed, 22 Nov 2023 20:39:46 -0500 Subject: [PATCH] add format to cycles to make look nice --- include/blt/std/format.h | 18 ++++++++++++++++++ src/blt/profiling/profiler_v2.cpp | 6 +++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/include/blt/std/format.h b/include/blt/std/format.h index 370c91a..d7ca0e6 100755 --- a/include/blt/std/format.h +++ b/include/blt/std/format.h @@ -11,9 +11,27 @@ #include #include #include +#include namespace blt::string { + template + static inline std::string withGrouping(T t, size_t group = 3){ + // TODO: all this + make it faster + static_assert(std::is_integral_v, "Must be integer type! (Floats currently not supported!)"); + auto str = std::to_string(t); + std::string ret; + ret.reserve(str.size()); + size_t count = 0; + for (int64_t i = str.size() - 1; i >= 0; i--){ + ret += str[i]; + if (count++ % (group) == group-1 && i != 0) + ret += ','; + } + std::reverse(ret.begin(), ret.end()); + return ret; + } + static inline std::string fromBytes(unsigned long bytes){ if (bytes > 1073741824) { // gigabyte diff --git a/src/blt/profiling/profiler_v2.cpp b/src/blt/profiling/profiler_v2.cpp index 87aec10..45f7449 100644 --- a/src/blt/profiling/profiler_v2.cpp +++ b/src/blt/profiling/profiler_v2.cpp @@ -39,8 +39,8 @@ namespace blt : static_cast(interval->thread_end - interval->thread_start); \ \ auto cycles = printHistory \ - ? (static_cast(interval->cycles_total) / static_cast(interval->count)) \ - : static_cast(interval->cycles_end - interval->cycles_start); + ? ((interval->cycles_total) / (interval->count)) \ + : (interval->cycles_end - interval->cycles_start); enum class unit { @@ -189,7 +189,7 @@ namespace blt row.rowValues.push_back(std::to_string(interval->count)); row.rowValues.push_back(interval->interval_name); if (printCycles) - row.rowValues.push_back(std::to_string(cycles)); + row.rowValues.push_back(blt::string::withGrouping(cycles)); if (printThread) row.rowValues.push_back(std::to_string(thread / static_cast(thread_unit_divide))); if (printWall)