Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
S
spdlog
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
spdlog
Commits
4a34cd06
Commit
4a34cd06
authored
Nov 12, 2018
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimized nano seconds formatting
parent
11d83515
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
4 deletions
+40
-4
formatter-bench.cpp
bench/formatter-bench.cpp
+2
-3
fmt_helper.h
include/spdlog/details/fmt_helper.h
+13
-0
pattern_formatter.h
include/spdlog/details/pattern_formatter.h
+2
-1
test_fmt_helper.cpp
tests/test_fmt_helper.cpp
+23
-0
No files found.
bench/formatter-bench.cpp
View file @
4a34cd06
...
...
@@ -50,8 +50,7 @@ void bench_formatters()
for
(
auto
&
flag
:
all_flags
)
{
auto
pattern
=
std
::
string
(
"%"
)
+
flag
;
benchmark
::
RegisterBenchmark
(
pattern
.
c_str
(),
bench_formatter
,
pattern
);
benchmark
::
RegisterBenchmark
(
pattern
.
c_str
(),
bench_formatter
,
pattern
)
->
Iterations
(
2500000
);
}
// complex patterns
...
...
@@ -62,7 +61,7 @@ void bench_formatters()
};
for
(
auto
&
pattern
:
patterns
)
{
benchmark
::
RegisterBenchmark
(
pattern
.
c_str
(),
bench_formatter
,
pattern
);
benchmark
::
RegisterBenchmark
(
pattern
.
c_str
(),
bench_formatter
,
pattern
)
->
Iterations
(
2500000
)
;
}
}
...
...
include/spdlog/details/fmt_helper.h
View file @
4a34cd06
...
...
@@ -110,6 +110,19 @@ inline void pad6(size_t n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
pad3
(
static_cast
<
int
>
(
n
%
1000
),
dest
);
}
template
<
size_t
Buffer_Size
>
inline
void
pad9
(
size_t
n
,
fmt
::
basic_memory_buffer
<
char
,
Buffer_Size
>
&
dest
)
{
if
(
n
>
99999999
)
{
append_int
(
n
,
dest
);
return
;
}
pad6
(
static_cast
<
int
>
(
n
/
1000
),
dest
);
pad3
(
static_cast
<
int
>
(
n
%
1000
),
dest
);
}
// return fraction of a second of the given time_point.
// e.g.
// fraction<std::milliseconds>(tp) -> will return the millis part of the second
...
...
include/spdlog/details/pattern_formatter.h
View file @
4a34cd06
...
...
@@ -486,7 +486,8 @@ public:
scoped_pad
p
(
field_size
,
padinfo_
,
dest
);
auto
ns
=
fmt_helper
::
time_fraction
<
std
::
chrono
::
nanoseconds
>
(
msg
.
time
);
fmt
::
format_to
(
dest
,
"{:09}"
,
ns
.
count
());
fmt_helper
::
pad9
(
static_cast
<
size_t
>
(
ns
.
count
()),
dest
);
}
};
...
...
tests/test_fmt_helper.cpp
View file @
4a34cd06
...
...
@@ -22,6 +22,13 @@ void test_pad6(std::size_t n, const char *expected)
REQUIRE
(
fmt
::
to_string
(
buf
)
==
expected
);
}
void
test_pad9
(
std
::
size_t
n
,
const
char
*
expected
)
{
fmt
::
memory_buffer
buf
;
spdlog
::
details
::
fmt_helper
::
pad9
(
n
,
buf
);
REQUIRE
(
fmt
::
to_string
(
buf
)
==
expected
);
}
TEST_CASE
(
"pad2"
,
"[fmt_helper]"
)
{
test_pad2
(
0
,
"00"
);
...
...
@@ -52,3 +59,19 @@ TEST_CASE("pad6", "[fmt_helper]")
test_pad6
(
12345
,
"012345"
);
test_pad6
(
123456
,
"123456"
);
}
TEST_CASE
(
"pad9"
,
"[fmt_helper]"
)
{
test_pad9
(
0
,
"000000000"
);
test_pad9
(
3
,
"000000003"
);
test_pad9
(
23
,
"000000023"
);
test_pad9
(
123
,
"000000123"
);
test_pad9
(
1234
,
"000001234"
);
test_pad9
(
12345
,
"000012345"
);
test_pad9
(
123456
,
"000123456"
);
test_pad9
(
1234567
,
"001234567"
);
test_pad9
(
12345678
,
"012345678"
);
test_pad9
(
123456789
,
"123456789"
);
test_pad9
(
1234567891
,
"1234567891"
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment