Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
ipgallery.common.cpp
/
Microservice
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Registry
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
611d8238
authored
Mar 08, 2017
by
amir
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
testing nlohman/json
parent
dbd42c46
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
2 deletions
test/Microservice_ClientTest.cpp
test/json.hpp
test/Microservice_ClientTest.cpp
View file @
611d8238
...
...
@@ -27,10 +27,14 @@
static
const
char
*
const
PUBSUBHOST
=
"zmqpubsub"
;
void
pubsubtest
(
cMicroservice_Client
*
p_Client
);
void
performance
(
cMicroservice_Client
*
p_Client
);
void
testRapidJson
();
void
runTest
()
{
cMicroservice_BaseClientParams
RMQClientParams
(
"MyFirstQ@test1"
,
false
,
0
,
false
,
"localhost"
,
5672
);
...
...
@@ -185,13 +189,75 @@ void pubsubtest(cMicroservice_Client *p_Client) {
// pcc->delByPattern(key);
//}
#include "json.hpp"
// for convenience
using
json
=
nlohmann
::
json
;
static
const
int
ITERATIONS
=
1000000
;
void
testRapidJson
()
{
for
(
int
i
=
0
;
i
<
ITERATIONS
;
i
++
)
{
std
::
string
json
;
rapidjson
::
Document
rpj_Doc
;
// Null
rapidjson
::
Document
::
AllocatorType
&
rpj_Alloc
=
rpj_Doc
.
GetAllocator
();
rpj_Doc
.
SetObject
();
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
"hello"
),
rapidjson
::
StringRef
(
"world"
),
rpj_Alloc
);
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
"number"
),
rapidjson
::
Value
(
i
),
rpj_Alloc
);
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
"status"
),
true
,
rpj_Alloc
);
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
"hello1"
),
rapidjson
::
StringRef
(
"world"
),
rpj_Alloc
);
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
"number1"
),
rapidjson
::
Value
(
i
),
rpj_Alloc
);
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
"status1"
),
true
,
rpj_Alloc
);
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
"hello2"
),
rapidjson
::
StringRef
(
"world"
),
rpj_Alloc
);
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
"number2"
),
rapidjson
::
Value
(
i
),
rpj_Alloc
);
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
"status2"
),
true
,
rpj_Alloc
);
rapidjson
::
StringBuffer
buffer
;
rapidjson
::
Writer
<
rapidjson
::
StringBuffer
>
writer
(
buffer
);
rpj_Doc
.
Accept
(
writer
);
json
.
assign
(
buffer
.
GetString
());
}
}
void
testNlohmanJson
()
{
for
(
int
i
=
0
;
i
<
ITERATIONS
;
i
++
)
{
std
::
string
jsonStr
;
json
j
;
j
.
emplace
(
"hello"
,
"world"
);
j
.
emplace
(
"number"
,
i
);
j
.
emplace
(
"status"
,
true
);
j
[
"hello1"
]
=
"world"
;
j
[
"number1"
]
=
i
;
j
[
"status1"
]
=
true
;
j
.
emplace
(
"hello2"
,
"world"
);
j
.
emplace
(
"number2"
,
i
);
j
.
emplace
(
"status2"
,
true
);
jsonStr
=
j
.
dump
();
}
}
void
testJsons
()
{
std
::
time_t
now
=
std
::
time
(
nullptr
);
testRapidJson
();
std
::
cout
<<
" Testing "
<<
ITERATIONS
<<
" with rapid json took: "
<<
std
::
time
(
nullptr
)
-
now
<<
"msec"
<<
'\n'
;
if
(
false
or
not
true
){
}
// test json-nlohman
now
=
std
::
time
(
nullptr
);
testNlohmanJson
();
std
::
cout
<<
" Testing "
<<
ITERATIONS
<<
" with nlohman json took: "
<<
std
::
time
(
nullptr
)
-
now
<<
"msec"
<<
'\n'
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
testJsons
();
// testCache();
//runTest();
runPubSubTest
();
//
runPubSubTest();
//runOldMS(argv);
...
...
test/json.hpp
0 → 100644
View file @
611d8238
This diff could not be displayed because it is too large.
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