Skip to content

Commit

Permalink
Merge pull request #197 from bbbgan/master
Browse files Browse the repository at this point in the history
 add sequential prase[json]
  • Loading branch information
bbbgan authored Jul 17, 2023
2 parents 7f5ddb1 + 1d3cc17 commit e6578c5
Show file tree
Hide file tree
Showing 7 changed files with 886 additions and 110 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ set(TEST_SOME test/test.cpp)
set(TEST_UT test/unit_test.cpp)
set(TEST_JSON_FILES test/test_json_files.cpp)
set(TEST_XML test/test_xml.cpp)
set(BENCHMARK benchmark/benchmark.cpp)
set(JSONBENCHMARK benchmark/json_benchmark.cpp)
set(XMLBENCH benchmark/xml_benchmark.cpp)
set(TEST_YAML test/test_yaml.cpp test/test_yaml_bech.cpp)
set(YAMLBENCH benchmark/yaml_benchmark.cpp)
Expand All @@ -62,7 +62,7 @@ add_executable(test_some ${TEST_SOME})
add_executable(test_ut ${TEST_UT})
add_executable(test_json_files ${TEST_JSON_FILES})
add_executable(test_xml ${TEST_XML})
add_executable(benchmark ${BENCHMARK})
add_executable(json_benchmark ${JSONBENCHMARK})
add_executable(xml_benchmark ${XMLBENCH})
add_executable(test_yaml ${TEST_YAML})
add_executable(yaml_benchmark ${YAMLBENCH})
Expand Down
21 changes: 6 additions & 15 deletions benchmark/benchmark.cpp → benchmark/json_benchmark.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
#include "iguana/json_reader.hpp"
#include "iguana/json_writer.hpp"
#include "iguana/value.hpp"
#include <chrono>
#include <iostream>
#include <map>
#include <tuple>
#ifdef HAS_RAPIDJSON
#include <rapidjson/document.h>
#include <rapidjson/writer.h>
#endif
#include "../test/test_headers.h"
#include "json_benchmark.h"

class ScopedTimer {
public:
Expand Down Expand Up @@ -202,9 +191,7 @@ obj_t create_object() {
void test_from_json(std::string filename, auto &obj, const auto &json_str,
const int size) {
iguana::from_json(obj, std::begin(json_str), std::end(json_str));

std::string iguana_str = "iguana from_json " + filename;

{
ScopedTimer timer(iguana_str.data());
for (int i = 0; i < size; ++i) {
Expand All @@ -215,12 +202,16 @@ void test_from_json(std::string filename, auto &obj, const auto &json_str,
#ifdef HAS_RAPIDJSON
rapidjson::Document doc;
doc.Parse(json_str.data(), json_str.size());
std::vector<std::string> json_str_arr(size);
for (int i = 0; i < size; ++i) {
json_str_arr[i] = json_str;
}
std::string rapidjson_str = "rapidjson parse " + filename;
{
ScopedTimer timer(rapidjson_str.data());
for (int i = 0; i < size; ++i) {
doc = {};
doc.Parse(json_str.data(), json_str.size());
doc.ParseInsitu(const_cast<char *>(json_str_arr[i].data()));
}
}
#endif
Expand Down
Loading

0 comments on commit e6578c5

Please sign in to comment.