Commit 611d8238 by amir

testing nlohman/json

parent dbd42c46
Showing with 67 additions and 1 deletions
......@@ -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);
......
This diff could not be displayed because it is too large.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment