Tables now have names
parent
c5f732342d
commit
060e1a8efb
|
@ -174,12 +174,13 @@ namespace blt::string {
|
||||||
|
|
||||||
class TableFormatter {
|
class TableFormatter {
|
||||||
private:
|
private:
|
||||||
|
std::string m_tableName;
|
||||||
int m_columnPadding;
|
int m_columnPadding;
|
||||||
int m_maxColumnWidth;
|
int m_maxColumnWidth;
|
||||||
std::vector<TableColumn> columns;
|
std::vector<TableColumn> columns;
|
||||||
std::vector<TableRow> rows;
|
std::vector<TableRow> rows;
|
||||||
|
|
||||||
static std::string generateTopSeparator(size_t size);
|
std::string generateTopSeparator(size_t size);
|
||||||
|
|
||||||
std::string generateColumnHeader();
|
std::string generateColumnHeader();
|
||||||
|
|
||||||
|
@ -192,8 +193,8 @@ namespace blt::string {
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit TableFormatter(int columnPadding = 2, int maxColumnWidth = 500):
|
explicit TableFormatter(std::string tableName = "", int columnPadding = 2, int maxColumnWidth = 500):
|
||||||
m_columnPadding(columnPadding), m_maxColumnWidth(maxColumnWidth) {}
|
m_tableName(std::move(tableName)), m_columnPadding(columnPadding), m_maxColumnWidth(maxColumnWidth) {}
|
||||||
|
|
||||||
inline void addColumn(const TableColumn& column) {
|
inline void addColumn(const TableColumn& column) {
|
||||||
columns.push_back(column);
|
columns.push_back(column);
|
||||||
|
|
|
@ -33,15 +33,16 @@ namespace blt::nbt {
|
||||||
if (readIndex == 0)
|
if (readIndex == 0)
|
||||||
m_stream.read(m_buffer, (long) m_bufferSize);
|
m_stream.read(m_buffer, (long) m_bufferSize);
|
||||||
if (readIndex + bytes >= m_bufferSize) {
|
if (readIndex + bytes >= m_bufferSize) {
|
||||||
|
// copy out all the data from the current buffer
|
||||||
auto bytesLeft = m_bufferSize - readIndex;
|
auto bytesLeft = m_bufferSize - readIndex;
|
||||||
memcpy(buffer, m_buffer + readIndex, bytesLeft);
|
memcpy(buffer, m_buffer + readIndex, bytesLeft);
|
||||||
readIndex = 0;
|
readIndex = 0;
|
||||||
bytes -= bytesLeft;
|
bytes -= bytesLeft;
|
||||||
readBytes(buffer + bytesLeft, bytes);
|
// now to prevent large scale reading in small blocks, we should just read the entire thing into the buffer.
|
||||||
// m_stream.read(m_buffer, (long) m_bufferSize);
|
m_stream.read(buffer + bytesLeft, (long) bytes);
|
||||||
// memcpy(buffer + bytesLeft, m_buffer, bytes);
|
|
||||||
// readIndex += bytes;
|
|
||||||
} else {
|
} else {
|
||||||
|
// but in the case that the size of the data read is small, we should read in blocks and copy from that buffer
|
||||||
|
// that should be quicker since file operations are slow.
|
||||||
std::memcpy(buffer, m_buffer + readIndex, bytes);
|
std::memcpy(buffer, m_buffer + readIndex, bytes);
|
||||||
readIndex += bytes;
|
readIndex += bytes;
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ namespace blt::profiling {
|
||||||
}
|
}
|
||||||
|
|
||||||
void printProfile(const std::string& profileName, int loggingLevel) {
|
void printProfile(const std::string& profileName, int loggingLevel) {
|
||||||
string::TableFormatter formatter;
|
string::TableFormatter formatter {profileName};
|
||||||
formatter.addColumn({"Interval"});
|
formatter.addColumn({"Interval"});
|
||||||
formatter.addColumn({"Time (ns)"});
|
formatter.addColumn({"Time (ns)"});
|
||||||
formatter.addColumn({"Time (ms)"});
|
formatter.addColumn({"Time (ms)"});
|
||||||
|
@ -105,7 +105,7 @@ namespace blt::profiling {
|
||||||
|
|
||||||
std::sort(unorderedIntervalVector.begin(), unorderedIntervalVector.end(), timeCompare);
|
std::sort(unorderedIntervalVector.begin(), unorderedIntervalVector.end(), timeCompare);
|
||||||
|
|
||||||
string::TableFormatter formatter;
|
string::TableFormatter formatter {profileName};
|
||||||
formatter.addColumn({"Order"});
|
formatter.addColumn({"Order"});
|
||||||
formatter.addColumn({"Interval"});
|
formatter.addColumn({"Interval"});
|
||||||
formatter.addColumn({"Time (ns)"});
|
formatter.addColumn({"Time (ns)"});
|
||||||
|
|
|
@ -68,10 +68,33 @@ std::string blt::string::TableFormatter::generateColumnHeader() {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string blt::string::TableFormatter::generateTopSeparator(size_t size) {
|
std::string blt::string::TableFormatter::generateTopSeparator(size_t size) {
|
||||||
std::string wholeWidthSeparator;
|
auto sizeOfName = m_tableName.empty() ? 0 : m_tableName.size() + 4;
|
||||||
for (int i = 0; i < size; i++)
|
auto sizeNameRemoved = size - sizeOfName;
|
||||||
wholeWidthSeparator += "-";
|
|
||||||
return wholeWidthSeparator;
|
std::string halfWidthLeftSeparator;
|
||||||
|
std::string halfWidthRightSeparator;
|
||||||
|
|
||||||
|
auto sizeNameFloor = (size_t) std::floor((double)sizeNameRemoved/2.0);
|
||||||
|
auto sizeNameCeil = (size_t) std::ceil((double)sizeNameRemoved/2.0);
|
||||||
|
|
||||||
|
halfWidthLeftSeparator.reserve(sizeNameCeil);
|
||||||
|
halfWidthRightSeparator.reserve(sizeNameFloor);
|
||||||
|
|
||||||
|
for (int i = 0; i < sizeNameFloor; i++)
|
||||||
|
halfWidthLeftSeparator += "-";
|
||||||
|
|
||||||
|
for (int i = 0; i < sizeNameCeil; i++)
|
||||||
|
halfWidthRightSeparator += "-";
|
||||||
|
|
||||||
|
std::string separator;
|
||||||
|
separator += halfWidthLeftSeparator;
|
||||||
|
if (sizeOfName != 0) {
|
||||||
|
separator += "{ ";
|
||||||
|
separator += m_tableName;
|
||||||
|
separator += " }";
|
||||||
|
}
|
||||||
|
separator += halfWidthRightSeparator;
|
||||||
|
return separator;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string blt::string::TableFormatter::generateSeparator(size_t size) {
|
std::string blt::string::TableFormatter::generateSeparator(size_t size) {
|
||||||
|
|
|
@ -12,6 +12,33 @@
|
||||||
#include <blt/std/logging.h>
|
#include <blt/std/logging.h>
|
||||||
#include <blt/std/format.h>
|
#include <blt/std/format.h>
|
||||||
|
|
||||||
|
struct nbt_scoped_buffer {
|
||||||
|
char* buffer;
|
||||||
|
size_t bufferSize;
|
||||||
|
explicit nbt_scoped_buffer(size_t bufferSize): bufferSize(bufferSize) {
|
||||||
|
buffer = new char[bufferSize];
|
||||||
|
}
|
||||||
|
~nbt_scoped_buffer(){
|
||||||
|
delete[] buffer;
|
||||||
|
}
|
||||||
|
inline char operator[](size_t index) const {
|
||||||
|
return buffer[index];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
inline bool readLargeBlockUsingNBTBufferedReader(const std::string& file, const nbt_scoped_buffer& bufferToCompare, size_t bufferSize) {
|
||||||
|
nbt_scoped_buffer read_buffer{bufferToCompare.bufferSize};
|
||||||
|
std::fstream largeBlockInputLarge(file, std::ios::in | std::ios::binary);
|
||||||
|
blt::nbt::NBTByteFStreamReader byteLargeBlockInputLarge(largeBlockInputLarge, bufferSize);
|
||||||
|
byteLargeBlockInputLarge.readBytes(read_buffer.buffer, bufferToCompare.bufferSize);
|
||||||
|
for (int i = 0; i < bufferToCompare.bufferSize; i++) {
|
||||||
|
if (read_buffer[i] != bufferToCompare.buffer[i])
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
largeBlockInputLarge.close();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
inline void nbt_tests(){
|
inline void nbt_tests(){
|
||||||
std::fstream testOutput("Hello.txt", std::ios::out | std::ios::binary);
|
std::fstream testOutput("Hello.txt", std::ios::out | std::ios::binary);
|
||||||
|
|
||||||
|
@ -43,52 +70,84 @@ inline void nbt_tests(){
|
||||||
BLT_INFO("%d, %c, %d, %d, %d, %s", testByteIn[0], testByteIn[1], testByteIn[2], testShortIn, testIntIn, strIn.c_str());
|
BLT_INFO("%d, %c, %d, %d, %d, %s", testByteIn[0], testByteIn[1], testByteIn[2], testShortIn, testIntIn, strIn.c_str());
|
||||||
|
|
||||||
|
|
||||||
auto bufferSize = 1024 * 1024;
|
constexpr auto bufferSize = 1024 * 128;
|
||||||
char* buffer = new char[bufferSize];
|
|
||||||
|
nbt_scoped_buffer buffer{bufferSize};
|
||||||
|
|
||||||
char* read_buffer = new char[bufferSize];
|
char* read_buffer = new char[bufferSize];
|
||||||
char* read_block_buffer = new char[bufferSize];
|
char* read_block_buffer = new char[bufferSize];
|
||||||
|
|
||||||
|
bool fstream_indv_correct = true;
|
||||||
|
bool fstream_large_correct = true;
|
||||||
|
bool nbt_block_indv_correct = true;
|
||||||
|
|
||||||
for (int i = 0; i < bufferSize; i++)
|
for (int i = 0; i < bufferSize; i++)
|
||||||
buffer[i] = i+1;
|
buffer.buffer[i] = i+1;
|
||||||
|
|
||||||
BLT_START_INTERVAL("nbt", "Raw Write");
|
BLT_START_INTERVAL("nbt", "Raw Write");
|
||||||
std::fstream largeOutput("HeyThere.txt", std::ios::out | std::ios::binary);
|
std::fstream largeOutput("HeyThere.txt", std::ios::out | std::ios::binary);
|
||||||
largeOutput.write(buffer, bufferSize);
|
largeOutput.write(buffer.buffer, bufferSize);
|
||||||
largeOutput.flush();
|
largeOutput.flush();
|
||||||
largeOutput.close();
|
largeOutput.close();
|
||||||
BLT_END_INTERVAL("nbt", "Raw Write");
|
BLT_END_INTERVAL("nbt", "Raw Write");
|
||||||
|
|
||||||
BLT_START_INTERVAL("nbt", "Raw Read");
|
BLT_START_INTERVAL("nbt", "Raw Read Individual");
|
||||||
std::fstream largeInput("HeyThere.txt", std::ios::in | std::ios::binary);
|
std::fstream largeInput("HeyThere.txt", std::ios::in | std::ios::binary);
|
||||||
largeInput.read(read_buffer, bufferSize);
|
|
||||||
largeInput.close();
|
|
||||||
BLT_END_INTERVAL("nbt", "Raw Read");
|
|
||||||
|
|
||||||
BLT_START_INTERVAL("nbt", "Block Read");
|
|
||||||
std::fstream largeBlockInput("HeyThere.txt", std::ios::in | std::ios::binary);
|
|
||||||
blt::nbt::NBTByteFStreamReader byteLargeBlockInput(largeBlockInput, 1024 * 128);
|
|
||||||
byteLargeBlockInput.readBytes(read_block_buffer, bufferSize);
|
|
||||||
largeBlockInput.close();
|
|
||||||
BLT_END_INTERVAL("nbt", "Block Read");
|
|
||||||
|
|
||||||
bool fstream_in_correct = true;
|
|
||||||
bool nbt_block_in_correct = true;
|
|
||||||
for (int i = 0; i < bufferSize; i++) {
|
for (int i = 0; i < bufferSize; i++) {
|
||||||
if (read_buffer[i] != buffer[i])
|
char byte;
|
||||||
fstream_in_correct = false;
|
largeInput.read(&byte, 1);
|
||||||
if (read_block_buffer[i] != buffer[i])
|
if (byte != buffer[i]) {
|
||||||
nbt_block_in_correct = false;
|
fstream_indv_correct = false;
|
||||||
if (!fstream_in_correct && !nbt_block_in_correct)
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
largeInput.close();
|
||||||
|
BLT_END_INTERVAL("nbt", "Raw Read Individual");
|
||||||
|
|
||||||
|
BLT_START_INTERVAL("nbt", "Block Read Individual");
|
||||||
|
std::fstream largeBlockInput("HeyThere.txt", std::ios::in | std::ios::binary);
|
||||||
|
blt::nbt::NBTByteFStreamReader byteLargeBlockInput(largeBlockInput, 1024 * 8);
|
||||||
|
for (int i = 0; i < bufferSize; i++) {
|
||||||
|
char byte;
|
||||||
|
byteLargeBlockInput.readBytes(&byte, 1);
|
||||||
|
if (byte != buffer[i]) {
|
||||||
|
nbt_block_indv_correct = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
largeBlockInput.close();
|
||||||
|
BLT_END_INTERVAL("nbt", "Block Read Individual");
|
||||||
|
|
||||||
|
BLT_START_INTERVAL("nbt", "Raw Read Large");
|
||||||
|
std::fstream largeInputLarge("HeyThere.txt", std::ios::in | std::ios::binary);
|
||||||
|
largeInputLarge.read(read_buffer, bufferSize);
|
||||||
|
for (int i = 0; i < bufferSize; i++) {
|
||||||
|
if (read_buffer[i] != buffer[i])
|
||||||
|
fstream_large_correct = false;
|
||||||
|
}
|
||||||
|
largeInputLarge.close();
|
||||||
|
BLT_END_INTERVAL("nbt", "Raw Read Large");
|
||||||
|
|
||||||
|
BLT_INFO("FStream Read Correctly? %s;", fstream_indv_correct ? "True" : "False");
|
||||||
|
BLT_INFO("FStream Large Read Correctly? %s;", fstream_large_correct ? "True" : "False");
|
||||||
|
BLT_INFO("NBT Block Stream Correctly? %s;\n", nbt_block_indv_correct ? "True" : "False");
|
||||||
|
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
auto size = (size_t) std::pow(2, 11 + i);
|
||||||
|
auto size_str = std::to_string(size);
|
||||||
|
auto profiler_string = "Block Read " + size_str;
|
||||||
|
bool nbt_block_large_correct = true;
|
||||||
|
BLT_START_INTERVAL("nbt", profiler_string);
|
||||||
|
nbt_block_large_correct = readLargeBlockUsingNBTBufferedReader("HeyThere.txt", buffer, size);
|
||||||
|
BLT_END_INTERVAL("nbt", profiler_string);
|
||||||
|
|
||||||
|
BLT_INFO("NBT Block %s Stream Correctly? %s;\n", size_str.c_str(), nbt_block_large_correct ? "True" : "False");
|
||||||
|
}
|
||||||
|
|
||||||
BLT_INFO("FStream Read Correctly? %s;", fstream_in_correct ? "True" : "False");
|
|
||||||
BLT_INFO("NBT Block Stream Correctly? %s;\n", nbt_block_in_correct ? "True" : "False");
|
|
||||||
BLT_PRINT_ORDERED("nbt");
|
BLT_PRINT_ORDERED("nbt");
|
||||||
|
|
||||||
delete[] read_buffer;
|
delete[] read_buffer;
|
||||||
delete[] read_block_buffer;
|
delete[] read_block_buffer;
|
||||||
delete[] buffer;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue