add format to cycles to make look nice

v1
Brett 2023-11-22 20:39:46 -05:00
parent f49147ca3d
commit 6514736262
2 changed files with 21 additions and 3 deletions

View File

@ -11,9 +11,27 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include <blt/math/math.h> #include <blt/math/math.h>
#include <algorithm>
namespace blt::string { namespace blt::string {
template<typename T>
static inline std::string withGrouping(T t, size_t group = 3){
// TODO: all this + make it faster
static_assert(std::is_integral_v<T>, "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){ static inline std::string fromBytes(unsigned long bytes){
if (bytes > 1073741824) { if (bytes > 1073741824) {
// gigabyte // gigabyte

View File

@ -39,8 +39,8 @@ namespace blt
: static_cast<double>(interval->thread_end - interval->thread_start); \ : static_cast<double>(interval->thread_end - interval->thread_start); \
\ \
auto cycles = printHistory \ auto cycles = printHistory \
? (static_cast<double>(interval->cycles_total) / static_cast<double>(interval->count)) \ ? ((interval->cycles_total) / (interval->count)) \
: static_cast<double>(interval->cycles_end - interval->cycles_start); : (interval->cycles_end - interval->cycles_start);
enum class unit enum class unit
{ {
@ -189,7 +189,7 @@ namespace blt
row.rowValues.push_back(std::to_string(interval->count)); row.rowValues.push_back(std::to_string(interval->count));
row.rowValues.push_back(interval->interval_name); row.rowValues.push_back(interval->interval_name);
if (printCycles) if (printCycles)
row.rowValues.push_back(std::to_string(cycles)); row.rowValues.push_back(blt::string::withGrouping(cycles));
if (printThread) if (printThread)
row.rowValues.push_back(std::to_string(thread / static_cast<double>(thread_unit_divide))); row.rowValues.push_back(std::to_string(thread / static_cast<double>(thread_unit_divide)));
if (printWall) if (printWall)