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
703a1d97
Commit
703a1d97
authored
Oct 01, 2016
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added g3log crush example
parent
6ce507ec
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
60 additions
and
46 deletions
+60
-46
bench/latency/Makefile
bench/latency/Makefile
+6
-2
bench/latency/g3log-crush.cpp
bench/latency/g3log-crush.cpp
+37
-0
bench/latency/g3log-latency.cpp
bench/latency/g3log-latency.cpp
+5
-19
bench/latency/spdlog-latency.cpp
bench/latency/spdlog-latency.cpp
+12
-25
No files found.
bench/latency/Makefile
View file @
703a1d97
CXX
?=
g++
CXX
?=
g++
CXXFLAGS
=
-march
=
native
-Wall
-std
=
c++11
-pthread
CXXFLAGS
=
-march
=
native
-Wall
-std
=
c++11
-pthread
CXX_RELEASE_FLAGS
=
-O
fast
-DNDEBUG
CXX_RELEASE_FLAGS
=
-O
2
-DNDEBUG
binaries
=
spdlog-latency g3log-latency
binaries
=
spdlog-latency g3log-latency
g3log-crush
all
:
$(binaries)
all
:
$(binaries)
...
@@ -15,6 +15,10 @@ spdlog-latency: spdlog-latency.cpp
...
@@ -15,6 +15,10 @@ spdlog-latency: spdlog-latency.cpp
g3log-latency
:
g3log-latency.cpp
g3log-latency
:
g3log-latency.cpp
$(CXX)
g3log-latency.cpp
-o
g3log-latency
$(CXXFLAGS)
$(CXX_RELEASE_FLAGS)
-I
../../../g3log/src
-L
.
-lg3logger
$(CXX)
g3log-latency.cpp
-o
g3log-latency
$(CXXFLAGS)
$(CXX_RELEASE_FLAGS)
-I
../../../g3log/src
-L
.
-lg3logger
g3log-crush
:
g3log-crush.cpp
$(CXX)
g3log-crush.cpp
-o
g3log-crush
$(CXXFLAGS)
$(CXX_RELEASE_FLAGS)
-I
../../../g3log/src
-L
.
-lg3logger
.PHONY
:
clean
.PHONY
:
clean
...
...
bench/latency/g3log-crush.cpp
0 → 100644
View file @
703a1d97
#include <iostream>
#include <g3log/g3log.hpp>
#include <g3log/logworker.hpp>
void
CrusherLoop
()
{
size_t
counter
=
0
;
while
(
true
)
{
LOGF
(
INFO
,
"Some text to crush you machine. thread:"
);
if
(
++
counter
%
1000000
==
0
)
{
std
::
cout
<<
"Wrote "
<<
counter
<<
" entries"
<<
std
::
endl
;
}
}
}
int
main
(
int
argc
,
char
**
argv
)
{
std
::
cout
<<
"WARNING: This test will exaust all your machine memory and will crush it!"
<<
std
::
endl
;
std
::
cout
<<
"Are you sure you want to continue ? "
<<
std
::
endl
;
char
c
;
std
::
cin
>>
c
;
if
(
toupper
(
c
)
!=
'Y'
)
return
0
;
auto
worker
=
g3
::
LogWorker
::
createLogWorker
();
auto
handle
=
worker
->
addDefaultLogger
(
argv
[
0
],
"g3log.txt"
);
g3
::
initializeLogging
(
worker
.
get
());
CrusherLoop
();
return
0
;
}
bench/latency/g3log-latency.cpp
View file @
703a1d97
//// to compile: c++ bench.cpp -o bench -Wall -Wshadow -Wextra -pedantic -std=c++11 -pthread -I../include -O3 -fPIC -Ofast -m64 -march=native
// Alternative: c++ bench.cpp -o bench -Wall -Wshadow -Wextra -pedantic -std=c++11 -pthread -I../include -O3 -march=native
// the test code itself is Public domain @ref: Unlicense.org
// made by KjellKod, 2015, first published for testing of g3log at github.com/kjellkod/g3log
// Feel free to share, modify etc with no obligations but also with no guarantees from my part either
// enjoy - Kjell Hedstrom (aka KjellKod)
//
//
// spdlog follows however another license. See the bottow of this file
//
#include <thread>
#include <thread>
#include <vector>
#include <vector>
#include <atomic>
#include <atomic>
...
@@ -52,7 +38,7 @@ void MeasurePeakDuringLogWrites(const size_t id, std::vector<uint64_t>& result)
...
@@ -52,7 +38,7 @@ void MeasurePeakDuringLogWrites(const size_t id, std::vector<uint64_t>& result)
}
}
auto
start_time
=
std
::
chrono
::
high_resolution_clock
::
now
();
auto
start_time
=
std
::
chrono
::
high_resolution_clock
::
now
();
LOGF
(
INFO
,
"Some text to log for thread: %ld"
,
id
);
LOGF
(
INFO
,
"Some text to log for thread: %ld"
,
id
);
auto
stop_time
=
std
::
chrono
::
high_resolution_clock
::
now
();
auto
stop_time
=
std
::
chrono
::
high_resolution_clock
::
now
();
uint64_t
time_us
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
microseconds
>
(
stop_time
-
start_time
).
count
();
uint64_t
time_us
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
microseconds
>
(
stop_time
-
start_time
).
count
();
result
.
push_back
(
time_us
);
result
.
push_back
(
time_us
);
...
@@ -73,13 +59,13 @@ void PrintResults(const std::map<size_t, std::vector<uint64_t>>& threads_result,
...
@@ -73,13 +59,13 @@ void PrintResults(const std::map<size_t, std::vector<uint64_t>>& threads_result,
// calc worst latenct
// calc worst latenct
auto
worst
=
*
std
::
max_element
(
all_measurements
.
begin
(),
all_measurements
.
end
());
auto
worst
=
*
std
::
max_element
(
all_measurements
.
begin
(),
all_measurements
.
end
());
// calc avg
// calc avg
auto
total
=
accumulate
(
begin
(
all_measurements
),
end
(
all_measurements
),
0
,
std
::
plus
<
uint64_t
>
());
auto
total
=
accumulate
(
begin
(
all_measurements
),
end
(
all_measurements
),
0
,
std
::
plus
<
uint64_t
>
());
auto
avg
=
double
(
total
)
/
all_measurements
.
size
();
auto
avg
=
double
(
total
)
/
all_measurements
.
size
();
std
::
cout
<<
"[g3log] worst: "
<<
std
::
setw
(
10
)
<<
std
::
right
<<
worst
<<
"
\t
Avg: "
<<
avg
<<
"
\t
Total: "
<<
utils
::
format
(
total_us
)
<<
" us"
<<
std
::
endl
;
std
::
cout
<<
"[g3log] worst: "
<<
std
::
setw
(
10
)
<<
std
::
right
<<
worst
<<
"
\t
Avg: "
<<
avg
<<
"
\t
Total: "
<<
utils
::
format
(
total_us
)
<<
" us"
<<
std
::
endl
;
}
}
}
// anonymous
}
// anonymous
...
@@ -120,10 +106,10 @@ int main(int argc, char** argv)
...
@@ -120,10 +106,10 @@ int main(int argc, char** argv)
const
std
::
string
g_prefix_log_name
=
"g3log-performance-"
;
const
std
::
string
g_prefix_log_name
=
"g3log-performance-"
;
const
std
::
string
g_measurement_dump
=
g_path
+
g_prefix_log_name
+
"_RESULT.txt"
;
const
std
::
string
g_measurement_dump
=
g_path
+
g_prefix_log_name
+
"_RESULT.txt"
;
auto
worker
=
g3
::
LogWorker
::
createLogWorker
();
auto
worker
=
g3
::
LogWorker
::
createLogWorker
();
auto
handle
=
worker
->
addDefaultLogger
(
argv
[
0
],
"g3log.txt"
);
auto
handle
=
worker
->
addDefaultLogger
(
argv
[
0
],
"g3log.txt"
);
g3
::
initializeLogging
(
worker
.
get
());
g3
::
initializeLogging
(
worker
.
get
());
auto
start_time_application_total
=
std
::
chrono
::
high_resolution_clock
::
now
();
auto
start_time_application_total
=
std
::
chrono
::
high_resolution_clock
::
now
();
for
(
uint64_t
idx
=
0
;
idx
<
number_of_threads
;
++
idx
)
for
(
uint64_t
idx
=
0
;
idx
<
number_of_threads
;
++
idx
)
{
{
...
...
bench/latency/spdlog-latency.cpp
View file @
703a1d97
//// to compile: c++ bench.cpp -o bench -Wall -Wshadow -Wextra -pedantic -std=c++11 -pthread -I../include -O3 -fPIC -Ofast -m64 -march=native
// Alternative: c++ bench.cpp -o bench -Wall -Wshadow -Wextra -pedantic -std=c++11 -pthread -I../include -O3 -march=native
// the test code itself is Public domain @ref: Unlicense.org
// made by KjellKod, 2015, first published for testing of g3log at github.com/kjellkod/g3log
// Feel free to share, modify etc with no obligations but also with no guarantees from my part either
// enjoy - Kjell Hedstrom (aka KjellKod)
//
//
// spdlog follows however another license. See the bottow of this file
//
#include <thread>
#include <thread>
#include <vector>
#include <vector>
...
@@ -40,7 +27,7 @@ std::atomic<size_t> g_counter = {0};
...
@@ -40,7 +27,7 @@ std::atomic<size_t> g_counter = {0};
void
MeasurePeakDuringLogWrites
(
const
size_t
id
,
std
::
vector
<
uint64_t
>&
result
)
void
MeasurePeakDuringLogWrites
(
const
size_t
id
,
std
::
vector
<
uint64_t
>&
result
)
{
{
auto
logger
=
spd
::
get
(
"file_logger"
);
auto
logger
=
spd
::
get
(
"file_logger"
);
while
(
true
)
while
(
true
)
{
{
const
size_t
value_now
=
++
g_counter
;
const
size_t
value_now
=
++
g_counter
;
...
@@ -70,13 +57,13 @@ void PrintResults(const std::map<size_t, std::vector<uint64_t>>& threads_result,
...
@@ -70,13 +57,13 @@ void PrintResults(const std::map<size_t, std::vector<uint64_t>>& threads_result,
// calc worst latenct
// calc worst latenct
auto
worst
=
*
std
::
max_element
(
all_measurements
.
begin
(),
all_measurements
.
end
());
auto
worst
=
*
std
::
max_element
(
all_measurements
.
begin
(),
all_measurements
.
end
());
// calc avg
// calc avg
auto
total
=
accumulate
(
begin
(
all_measurements
),
end
(
all_measurements
),
0
,
std
::
plus
<
uint64_t
>
());
auto
total
=
accumulate
(
begin
(
all_measurements
),
end
(
all_measurements
),
0
,
std
::
plus
<
uint64_t
>
());
auto
avg
=
double
(
total
)
/
all_measurements
.
size
();
auto
avg
=
double
(
total
)
/
all_measurements
.
size
();
std
::
cout
<<
"[spdlog] worst: "
<<
std
::
setw
(
10
)
<<
std
::
right
<<
worst
<<
"
\t
Avg: "
<<
avg
<<
"
\t
Total: "
<<
utils
::
format
(
total_us
)
<<
" us"
<<
std
::
endl
;
std
::
cout
<<
"[spdlog] worst: "
<<
std
::
setw
(
10
)
<<
std
::
right
<<
worst
<<
"
\t
Avg: "
<<
avg
<<
"
\t
Total: "
<<
utils
::
format
(
total_us
)
<<
" us"
<<
std
::
endl
;
}
}
}
// anonymous
}
// anonymous
...
@@ -114,13 +101,13 @@ int main(int argc, char** argv)
...
@@ -114,13 +101,13 @@ int main(int argc, char** argv)
}
}
int
queue_size
=
1048576
;
// 2 ^ 20
int
queue_size
=
1048576
;
// 2 ^ 20
spdlog
::
set_async_mode
(
queue_size
);
spdlog
::
set_async_mode
(
queue_size
);
auto
logger
=
spdlog
::
create
<
spd
::
sinks
::
simple_file_sink_mt
>
(
"file_logger"
,
"spdlog.log"
,
true
);
auto
logger
=
spdlog
::
create
<
spd
::
sinks
::
simple_file_sink_mt
>
(
"file_logger"
,
"spdlog.log"
,
true
);
//force flush on every call to compare with g3log
//force flush on every call to compare with g3log
auto
s
=
(
spd
::
sinks
::
simple_file_sink_mt
*
)
logger
->
sinks
()[
0
].
get
();
auto
s
=
(
spd
::
sinks
::
simple_file_sink_mt
*
)
logger
->
sinks
()[
0
].
get
();
s
->
set_force_flush
(
true
);
s
->
set_force_flush
(
true
);
auto
start_time_application_total
=
std
::
chrono
::
high_resolution_clock
::
now
();
auto
start_time_application_total
=
std
::
chrono
::
high_resolution_clock
::
now
();
for
(
uint64_t
idx
=
0
;
idx
<
number_of_threads
;
++
idx
)
for
(
uint64_t
idx
=
0
;
idx
<
number_of_threads
;
++
idx
)
{
{
...
...
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