Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
macaon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Franck Dary
macaon
Commits
adce02c5
Commit
adce02c5
authored
5 years ago
by
Franck Dary
Browse files
Options
Downloads
Patches
Plain Diff
Improved size computation
parent
5646953f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
common/include/util.hpp
+30
-1
30 additions, 1 deletion
common/include/util.hpp
reading_machine/include/Config.hpp
+9
-0
9 additions, 0 deletions
reading_machine/include/Config.hpp
reading_machine/src/Config.cpp
+15
-9
15 additions, 9 deletions
reading_machine/src/Config.cpp
with
54 additions
and
10 deletions
common/include/util.hpp
+
30
−
1
View file @
adce02c5
...
...
@@ -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
<
>
...
...
This diff is collapsed.
Click to expand it.
reading_machine/include/Config.hpp
+
9
−
0
View file @
adce02c5
...
...
@@ -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
);
...
...
This diff is collapsed.
Click to expand it.
reading_machine/src/Config.cpp
+
15
−
9
View file @
adce02c5
...
...
@@ -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
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment