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
74e8bebb
Commit
74e8bebb
authored
Aug 05, 2018
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added async_bench
parent
8bfec30d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
136 additions
and
2 deletions
+136
-2
bench/Makefile
bench/Makefile
+6
-2
bench/async_bench.cpp
bench/async_bench.cpp
+130
-0
No files found.
bench/Makefile
View file @
74e8bebb
CXX
=
g++
CXX
?
=
g++
CXXFLAGS
=
-march
=
native
-Wall
-Wextra
-pedantic
-std
=
c++11
-pthread
-I
../include
-fmax-errors
=
1
CXX_RELEASE_FLAGS
=
-Ofast
-flto
-Wl
,--no-as-needed
binaries
=
bench latency
binaries
=
bench latency
async_bench
all
:
$(binaries)
bench
:
bench.cpp
$(CXX)
bench.cpp
-o
bench
$(CXXFLAGS)
$(CXX_RELEASE_FLAGS)
async_bench
:
async_bench.cpp
$(CXX)
async_bench.cpp
-o
async_bench
$(CXXFLAGS)
$(CXX_RELEASE_FLAGS)
latency
:
latency.cpp
$(CXX)
latency.cpp
-o
latency
$(CXXFLAGS)
$(CXX_RELEASE_FLAGS)
...
...
bench/async_bench.cpp
0 → 100644
View file @
74e8bebb
//
// Copyright(c) 2015 Gabi Melman.
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
//
//
// bench.cpp : spdlog benchmarks
//
#include "spdlog/async.h"
#include "spdlog/sinks/basic_file_sink.h"
#include "spdlog/sinks/stdout_color_sinks.h"
#include "spdlog/spdlog.h"
#include "utils.h"
#include <atomic>
#include <iostream>
#include <memory>
#include <string>
#include <thread>
using
namespace
std
;
using
namespace
std
::
chrono
;
using
namespace
spdlog
;
using
namespace
spdlog
::
sinks
;
using
namespace
utils
;
void
bench_mt
(
int
howmany
,
std
::
shared_ptr
<
spdlog
::
logger
>
log
,
int
thread_count
);
int
count_lines
(
const
char
*
filename
)
{
int
counter
=
0
;
auto
*
infile
=
fopen
(
filename
,
"r"
);
int
ch
;
while
(
EOF
!=
(
ch
=
getc
(
infile
)))
{
if
(
'\n'
==
ch
)
counter
++
;
}
return
counter
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
howmany
=
1000000
;
int
queue_size
=
howmany
+
2
;
int
threads
=
10
;
int
iters
=
3
;
try
{
auto
console
=
spdlog
::
stdout_color_mt
(
"console"
);
if
(
argc
==
1
)
{
console
->
set_pattern
(
"%v"
);
console
->
info
(
"Usage: {} <message_count> <threads> <q_size> <iterations>"
,
argv
[
0
]);
return
0
;
}
if
(
argc
>
1
)
howmany
=
atoi
(
argv
[
1
]);
if
(
argc
>
2
)
threads
=
atoi
(
argv
[
2
]);
if
(
argc
>
3
)
queue_size
=
atoi
(
argv
[
3
]);
if
(
argc
>
4
)
iters
=
atoi
(
argv
[
4
]);
console
->
info
(
"-------------------------------------------------"
);
console
->
info
(
"Messages: {:14n}"
,
howmany
);
console
->
info
(
"Threads : {:14n}"
,
threads
);
console
->
info
(
"Queue : {:14n}"
,
queue_size
);
console
->
info
(
"Iters : {:>14n}"
,
iters
);
console
->
info
(
"-------------------------------------------------"
);
const
char
*
filename
=
"logs/basic_async.log"
;
for
(
int
i
=
0
;
i
<
iters
;
i
++
)
{
auto
tp
=
std
::
make_shared
<
details
::
thread_pool
>
(
queue_size
,
1
);
auto
file_sink
=
std
::
make_shared
<
spdlog
::
sinks
::
basic_file_sink_mt
>
(
filename
,
true
);
auto
logger
=
std
::
make_shared
<
async_logger
>
(
"async_logger"
,
std
::
move
(
file_sink
),
std
::
move
(
tp
),
async_overflow_policy
::
block
);
bench_mt
(
howmany
,
std
::
move
(
logger
),
threads
);
auto
count
=
count_lines
(
filename
);
if
(
count
!=
howmany
)
{
console
->
error
(
"Test failed. {} has {:n} lines instead of {:n}"
,
filename
,
count
,
howmany
);
exit
(
1
);
}
else
{
console
->
info
(
"Line count OK ({:n})
\n
"
,
count
);
}
}
}
catch
(
std
::
exception
&
ex
)
{
std
::
cerr
<<
"Error: "
<<
ex
.
what
()
<<
std
::
endl
;
perror
(
"Last error"
);
return
1
;
}
return
0
;
}
void
bench_mt
(
int
howmany
,
std
::
shared_ptr
<
spdlog
::
logger
>
log
,
int
thread_count
)
{
using
std
::
chrono
::
high_resolution_clock
;
vector
<
thread
>
threads
;
auto
start
=
high_resolution_clock
::
now
();
for
(
int
t
=
0
;
t
<
thread_count
;
++
t
)
{
threads
.
push_back
(
std
::
thread
([
&
]()
{
for
(
int
j
=
0
;
j
<
howmany
/
thread_count
;
j
++
)
{
log
->
info
(
"Hello logger: msg number {}"
,
j
);
}
}));
}
for
(
auto
&
t
:
threads
)
{
t
.
join
();
};
auto
delta
=
high_resolution_clock
::
now
()
-
start
;
auto
delta_d
=
duration_cast
<
duration
<
double
>>
(
delta
).
count
();
spdlog
::
get
(
"console"
)
->
info
(
"Elapsed: {} secs
\t
{:n}/sec"
,
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