Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
spdlog
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
spdlog
Commits
18ed04b9
Commit
18ed04b9
authored
Apr 09, 2020
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed clang-tidy warnings in bench.cpp
parent
d09e0360
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
17 deletions
+39
-17
bench/bench.cpp
bench/bench.cpp
+39
-17
No files found.
bench/bench.cpp
View file @
18ed04b9
...
...
@@ -19,19 +19,15 @@
#include <string>
#include <thread>
using
namespace
std
;
using
namespace
std
::
chrono
;
using
namespace
spdlog
;
using
namespace
spdlog
::
sinks
;
using
namespace
utils
;
void
bench
(
int
howmany
,
std
::
shared_ptr
<
spdlog
::
logger
>
log
);
void
bench_mt
(
int
howmany
,
std
::
shared_ptr
<
spdlog
::
logger
>
log
,
int
thread_count
);
void
bench_default_api
(
int
howmany
,
std
::
shared_ptr
<
spdlog
::
logger
>
log
);
void
bench_c_string
(
int
howmany
,
std
::
shared_ptr
<
spdlog
::
logger
>
log
);
static
size_t
file_size
=
30
*
1024
*
1024
;
static
size_t
rotating_files
=
5
;
// void bench_default_api(int howmany, std::shared_ptr<spdlog::logger> log);
// void bench_c_string(int howmany, std::shared_ptr<spdlog::logger> log);
static
const
size_t
file_size
=
30
*
1024
*
1024
;
static
const
size_t
rotating_files
=
5
;
static
const
int
max_threads
=
1000
;
void
bench_threaded_logging
(
int
threads
,
int
iters
)
{
...
...
@@ -116,9 +112,18 @@ int main(int argc, char *argv[])
{
if
(
argc
>
1
)
iters
=
atoi
(
argv
[
1
]);
{
iters
=
std
::
stoi
(
argv
[
1
]);
}
if
(
argc
>
2
)
threads
=
atoi
(
argv
[
2
]);
{
threads
=
std
::
stoi
(
argv
[
2
]);
}
if
(
threads
>
max_threads
)
{
throw
std
::
runtime_error
(
fmt
::
format
(
"Number of threads exceeds maximum({}})"
,
max_threads
));
}
bench_single_threaded
(
iters
);
bench_threaded_logging
(
1
,
iters
);
...
...
@@ -135,6 +140,9 @@ int main(int argc, char *argv[])
void
bench
(
int
howmany
,
std
::
shared_ptr
<
spdlog
::
logger
>
log
)
{
using
std
::
chrono
::
high_resolution_clock
;
using
std
::
chrono
::
duration
;
using
std
::
chrono
::
duration_cast
;
auto
start
=
high_resolution_clock
::
now
();
for
(
auto
i
=
0
;
i
<
howmany
;
++
i
)
{
...
...
@@ -151,16 +159,20 @@ void bench(int howmany, std::shared_ptr<spdlog::logger> log)
void
bench_mt
(
int
howmany
,
std
::
shared_ptr
<
spdlog
::
logger
>
log
,
int
thread_count
)
{
using
std
::
chrono
::
high_resolution_clock
;
vector
<
thread
>
threads
;
using
std
::
chrono
::
duration
;
using
std
::
chrono
::
duration_cast
;
std
::
vector
<
std
::
thread
>
threads
;
threads
.
reserve
(
thread_count
);
auto
start
=
high_resolution_clock
::
now
();
for
(
int
t
=
0
;
t
<
thread_count
;
++
t
)
{
threads
.
push_back
(
std
::
thread
([
&
]()
{
threads
.
emplace_back
([
&
]()
{
for
(
int
j
=
0
;
j
<
howmany
/
thread_count
;
j
++
)
{
log
->
info
(
"Hello logger: msg number {}"
,
j
);
}
})
)
;
});
}
for
(
auto
&
t
:
threads
)
...
...
@@ -174,9 +186,13 @@ void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count
spdlog
::
drop
(
log
->
name
());
}
/*
void bench_default_api(int howmany, std::shared_ptr<spdlog::logger> log)
{
using std::chrono::high_resolution_clock;
using std::chrono::duration;
using std::chrono::duration_cast;
auto orig_default = spdlog::default_logger();
spdlog::set_default_logger(log);
auto start = high_resolution_clock::now();
...
...
@@ -194,18 +210,22 @@ void bench_default_api(int howmany, std::shared_ptr<spdlog::logger> log)
void bench_c_string(int howmany, std::shared_ptr<spdlog::logger> log)
{
using std::chrono::high_resolution_clock;
using std::chrono::duration;
using std::chrono::duration_cast;
const char *msg = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum pharetra metus cursus "
"lacus placerat congue. Nulla egestas, mauris a tincidunt tempus, enim lectus volutpat mi, eu consequat sem "
"libero nec massa. In dapibus ipsum a diam rhoncus gravida. Etiam non dapibus eros. Donec fringilla dui sed "
"augue pretium, nec scelerisque est maximus. Nullam convallis, sem nec blandit maximus, nisi turpis ornare "
"nisl, sit amet volutpat neque massa eu odio. Maecenas malesuada quam ex, posuere congue nibh turpis duis.";
using
std
::
chrono
::
high_resolution_clock
;
auto orig_default = spdlog::default_logger();
spdlog::set_default_logger(log);
auto start = high_resolution_clock::now();
for (auto i = 0; i < howmany; ++i)
{
spdlog
::
log
(
level
::
info
,
msg
);
spdlog::log(
spdlog::
level::info, msg);
}
auto delta = high_resolution_clock::now() - start;
...
...
@@ -214,3 +234,5 @@ void bench_c_string(int howmany, std::shared_ptr<spdlog::logger> log)
spdlog::set_default_logger(std::move(orig_default));
spdlog::info("{:<30} Elapsed: {:0.2f} secs {:>16n}/sec", log->name(), delta_d, int(howmany / delta_d));
}
*/
\ No newline at end of file
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