Skip to content
Snippets Groups Projects
Commit adce02c5 authored by Franck Dary's avatar Franck Dary
Browse files

Improved size computation

parent 5646953f
No related branches found
No related tags found
No related merge requests found
......@@ -17,11 +17,11 @@
#include <string>
#include <vector>
#include <array>
#include <unordered_map>
#include <fmt/core.h>
#include <experimental/source_location>
#include "utf8.hpp"
namespace util
{
typedef std::array<char, 4> utf8char;
......@@ -39,6 +39,35 @@ void myThrow(std::string_view message, const std::experimental::source_location
std::string int2HumanStr(int number);
template<typename T>
std::size_t memorySize(const T & val)
{
myThrow("Type not yet supported");
return sizeof val;
}
inline std::size_t memorySize(int val)
{
return sizeof val;
}
template<typename T>
std::size_t memorySize(const std::basic_string<T> & val)
{
return sizeof val + val.capacity() * sizeof (T);
}
template<typename T>
std::size_t memorySize(const std::vector<T> & vec)
{
std::size_t result = sizeof vec + sizeof (T) * (vec.capacity()-vec.size());
for (auto & elem : vec)
result += memorySize(elem);
return result;
}
};
template <>
......
......@@ -19,6 +19,13 @@
#include <unordered_map>
#include "util.hpp"
class Config;
namespace util
{
std::size_t memorySize(const Config & c);
};
class Config
{
public :
......@@ -45,6 +52,8 @@ class Config
void readRawInput(std::string_view rawFilename);
void readTSVInput(std::string_view tsvFilename);
friend std::size_t util::memorySize(const Config &);
public :
Config(std::string_view mcdFilename, std::string_view tsvFilename, std::string_view rawFilename);
......
......@@ -97,7 +97,9 @@ void Config::readTSVInput(std::string_view tsvFilename)
lines.back().emplace_back();
lines.back().back().emplace_back("");
}
lines.back()[colName2Index[EOSColName]][0] = EOSSymbol0;
for (unsigned int i = 0; i < splited.size(); i++)
if (i < colIndex2Name.size())
lines.back()[i][0] = splited[i];
......@@ -108,21 +110,20 @@ void Config::readTSVInput(std::string_view tsvFilename)
void Config::printSize(FILE * dest)
{
int rawInputNbElements = rawInput.size();
int rawInputSize = sizeof rawInput + rawInput.capacity() * sizeof rawInput[0];
int rawInputUtf8NbElements = 4*rawInputUtf8.size();
int rawInputUtf8Size = sizeof rawInputUtf8 + rawInputUtf8.capacity()* sizeof rawInputUtf8[0];
int rawInputSize = util::memorySize(rawInput);
int rawInputUtf8Size = util::memorySize(rawInputUtf8);
int linesSize = util::memorySize(lines);
int totalSize = rawInputSize + rawInputUtf8Size;
int totalSize = rawInputSize + rawInputUtf8Size + linesSize;
std::string unit = "Mo";
int unitPower = 6;
float unitMultiplier = std::stof(fmt::format("0.{:0^{}}1","",unitPower-1));
fmt::print(dest, "{:<43} : {:<{}.2f} {}\n", fmt::format("{:<20} {:>12} elements", "rawInput", util::int2HumanStr(rawInputNbElements)), unitMultiplier*rawInputSize, 2+11-unitPower, unit);
fmt::print(dest, "{:<43} : {:<{}.2f} {}\n", fmt::format("{:<20} {:>12} elements", "rawInputUtf8", util::int2HumanStr(rawInputUtf8NbElements)), unitMultiplier*rawInputUtf8Size, 2+11-unitPower, unit);
fmt::print(dest, "{:<43} : {:<{}.2f} {}\n", "Total", unitMultiplier*totalSize, 2+11-unitPower, unit);
fmt::print(dest, "{:<15} : {:<{}.2f} {}\n", "rawInput", unitMultiplier*rawInputSize, 2+11-unitPower, unit);
fmt::print(dest, "{:<15} : {:<{}.2f} {}\n", "rawInputUtf8", unitMultiplier*rawInputUtf8Size, 2+11-unitPower, unit);
fmt::print(dest, "{:<15} : {:<{}.2f} {}\n", "lines", unitMultiplier*linesSize, 2+11-unitPower, unit);
fmt::print(dest, "{:<15} : {:<{}.2f} {}\n", "Total", unitMultiplier*totalSize, 2+11-unitPower, unit);
}
Config::Config(std::string_view mcdFilename, std::string_view tsvFilename, std::string_view rawFilename)
......@@ -152,3 +153,8 @@ void Config::print(FILE * dest) const
}
}
std::size_t util::memorySize(const Config & c)
{
return sizeof c + memorySize(c.rawInput) + memorySize(c.rawInputUtf8) + memorySize(c.lines) + memorySize(c.colIndex2Name) + memorySize(c.colName2Index);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment