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
13cc6478
Commit
13cc6478
authored
Oct 16, 2018
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bench: eat our own dog food
parent
c465250c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
33 deletions
+23
-33
bench/bench.cpp
bench/bench.cpp
+23
-33
No files found.
bench/bench.cpp
View file @
13cc6478
...
...
@@ -16,7 +16,6 @@
#include "utils.h"
#include <atomic>
#include <cstdlib> // EXIT_FAILURE
#include <iostream>
#include <memory>
#include <string>
#include <thread>
...
...
@@ -34,6 +33,7 @@ void bench_default_api(int howmany, std::shared_ptr<spdlog::logger> log);
int
main
(
int
argc
,
char
*
argv
[])
{
spdlog
::
default_logger
()
->
set_pattern
(
"[%^%l%$] %v"
);
int
howmany
=
1000000
;
int
queue_size
=
howmany
+
2
;
int
threads
=
10
;
...
...
@@ -50,11 +50,10 @@ int main(int argc, char *argv[])
if
(
argc
>
3
)
queue_size
=
atoi
(
argv
[
3
]);
cout
<<
"******************************************************************"
"*************
\n
"
;
cout
<<
"Single thread, "
<<
format
(
howmany
)
<<
" iterations"
<<
endl
;
cout
<<
"******************************************************************"
"*************
\n
"
;
spdlog
::
info
(
"**************************************************************"
);
spdlog
::
info
(
"Single thread, {:n} iterations"
,
howmany
);
spdlog
::
info
(
"**************************************************************"
);
auto
basic_st
=
spdlog
::
basic_logger_st
(
"basic_st"
,
"logs/basic_st.log"
,
true
);
bench
(
howmany
,
std
::
move
(
basic_st
));
...
...
@@ -68,11 +67,9 @@ int main(int argc, char *argv[])
bench
(
howmany
,
spdlog
::
create
<
null_sink_st
>
(
"null_st"
));
cout
<<
"******************************************************************"
"*************
\n
"
;
cout
<<
"Default API. Single thread, "
<<
format
(
howmany
)
<<
" iterations"
<<
endl
;
cout
<<
"******************************************************************"
"*************
\n
"
;
spdlog
::
info
(
"**************************************************************"
);
spdlog
::
info
(
"Default API. Single thread, {:n} iterations"
,
howmany
);
spdlog
::
info
(
"**************************************************************"
);
basic_st
=
spdlog
::
basic_logger_st
(
"basic_st"
,
"logs/basic_st.log"
,
true
);
bench_default_api
(
howmany
,
std
::
move
(
basic_st
));
...
...
@@ -85,11 +82,9 @@ int main(int argc, char *argv[])
bench_default_api
(
howmany
,
spdlog
::
create
<
null_sink_st
>
(
"null_st"
));
cout
<<
"
\n
****************************************************************"
"***************
\n
"
;
cout
<<
threads
<<
" threads sharing same logger, "
<<
format
(
howmany
)
<<
" iterations"
<<
endl
;
cout
<<
"******************************************************************"
"*************
\n
"
;
spdlog
::
info
(
"**************************************************************"
);
spdlog
::
info
(
"{:n} threads sharing same logger, {:n} iterations"
,
threads
,
howmany
);
spdlog
::
info
(
"**************************************************************"
);
auto
basic_mt
=
spdlog
::
basic_logger_mt
(
"basic_mt"
,
"logs/basic_mt.log"
,
true
);
bench_mt
(
howmany
,
std
::
move
(
basic_mt
),
threads
);
...
...
@@ -101,11 +96,9 @@ int main(int argc, char *argv[])
bench_mt
(
howmany
,
std
::
move
(
daily_mt
),
threads
);
bench_mt
(
howmany
,
spdlog
::
create
<
null_sink_mt
>
(
"null_mt"
),
threads
);
cout
<<
"
\n
****************************************************************"
"***************
\n
"
;
cout
<<
"async logging.. "
<<
threads
<<
" threads sharing same logger, "
<<
format
(
howmany
)
<<
" iterations "
<<
endl
;
cout
<<
"******************************************************************"
"*************
\n
"
;
spdlog
::
info
(
"**************************************************************"
);
spdlog
::
info
(
"Asyncronous.. {:n} threads sharing same logger, {:n} iterations"
,
threads
,
howmany
);
spdlog
::
info
(
"**************************************************************"
);
for
(
int
i
=
0
;
i
<
3
;
++
i
)
{
...
...
@@ -116,8 +109,7 @@ int main(int argc, char *argv[])
}
catch
(
std
::
exception
&
ex
)
{
std
::
cerr
<<
"Error: "
<<
ex
.
what
()
<<
std
::
endl
;
perror
(
"Last error"
);
spdlog
::
error
(
ex
.
what
());
return
EXIT_FAILURE
;
}
return
EXIT_SUCCESS
;
...
...
@@ -126,7 +118,6 @@ int main(int argc, char *argv[])
void
bench
(
int
howmany
,
std
::
shared_ptr
<
spdlog
::
logger
>
log
)
{
using
std
::
chrono
::
high_resolution_clock
;
cout
<<
log
->
name
()
<<
"...
\t\t
"
<<
flush
;
auto
start
=
high_resolution_clock
::
now
();
for
(
auto
i
=
0
;
i
<
howmany
;
++
i
)
{
...
...
@@ -136,14 +127,13 @@ void bench(int howmany, std::shared_ptr<spdlog::logger> log)
auto
delta
=
high_resolution_clock
::
now
()
-
start
;
auto
delta_d
=
duration_cast
<
duration
<
double
>>
(
delta
).
count
();
cout
<<
"Elapsed: "
<<
delta_d
<<
"
\t
"
<<
format
(
int
(
howmany
/
delta_d
))
<<
"/sec"
<<
endl
;
spdlog
::
drop
_all
(
);
spdlog
::
info
(
"{:<16} Elapsed: {:0.2f} secs {:>16n}/sec"
,
log
->
name
(),
delta_d
,
int
(
howmany
/
delta_d
))
;
spdlog
::
drop
(
log
->
name
()
);
}
void
bench_mt
(
int
howmany
,
std
::
shared_ptr
<
spdlog
::
logger
>
log
,
int
thread_count
)
{
using
std
::
chrono
::
high_resolution_clock
;
cout
<<
log
->
name
()
<<
"...
\t\t
"
<<
flush
;
vector
<
thread
>
threads
;
auto
start
=
high_resolution_clock
::
now
();
for
(
int
t
=
0
;
t
<
thread_count
;
++
t
)
...
...
@@ -163,14 +153,14 @@ void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count
auto
delta
=
high_resolution_clock
::
now
()
-
start
;
auto
delta_d
=
duration_cast
<
duration
<
double
>>
(
delta
).
count
();
cout
<<
"Elapsed: "
<<
delta_d
<<
"
\t
"
<<
format
(
int
(
howmany
/
delta_d
))
<<
"/sec"
<<
endl
;
spdlog
::
drop
_all
(
);
spdlog
::
info
(
"{:<16} Elapsed: {:0.2f} secs {:>16n}/sec"
,
log
->
name
(),
delta_d
,
int
(
howmany
/
delta_d
))
;
spdlog
::
drop
(
log
->
name
()
);
}
void
bench_default_api
(
int
howmany
,
std
::
shared_ptr
<
spdlog
::
logger
>
log
)
{
using
std
::
chrono
::
high_resolution_clock
;
cout
<<
log
->
name
()
<<
"...
\t\t
"
<<
flush
;
auto
orig_default
=
spdlog
::
default_logger
()
;
spdlog
::
set_default_logger
(
log
);
auto
start
=
high_resolution_clock
::
now
();
for
(
auto
i
=
0
;
i
<
howmany
;
++
i
)
...
...
@@ -180,7 +170,7 @@ void bench_default_api(int howmany, std::shared_ptr<spdlog::logger> log)
auto
delta
=
high_resolution_clock
::
now
()
-
start
;
auto
delta_d
=
duration_cast
<
duration
<
double
>>
(
delta
).
count
();
cout
<<
"Elapsed: "
<<
delta_d
<<
"
\t
"
<<
format
(
int
(
howmany
/
delta_d
))
<<
"/sec"
<<
endl
;
spdlog
::
drop_all
(
);
spdlog
::
drop
(
log
->
name
());
spdlog
::
set_default_logger
(
std
::
move
(
orig_default
))
;
spdlog
::
info
(
"{:<16} Elapsed: {:0.2f} secs {:>16n}/sec"
,
log
->
name
(),
delta_d
,
int
(
howmany
/
delta_d
)
);
}
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