mirror of
https://github.com/nlohmann/json.git
synced 2026-09-02 22:47:14 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
984893f753 | ||
|
|
1de8915313 | ||
|
|
85756b50cd | ||
|
|
12016a69a8 | ||
|
|
7db19dbf91 |
@@ -850,16 +850,15 @@ class serializer
|
||||
// for the scan. Without it, text whose characters all have to be
|
||||
// escaped - CJK under ensure_ascii, where every byte is >= 0x80 -
|
||||
// runs the scanner once per character only to be told zero.
|
||||
const std::size_t run = [&]() -> std::size_t
|
||||
std::size_t run = 0;
|
||||
if (!EnsureAscii)
|
||||
{
|
||||
if (EnsureAscii)
|
||||
{
|
||||
return is_ascii_copyable(data[i])
|
||||
? find_ascii_copyable_run(data + i, s.size() - i)
|
||||
: 0;
|
||||
}
|
||||
return string_bulk_run(data + i, s.size() - i);
|
||||
}();
|
||||
run = string_bulk_run(data + i, s.size() - i);
|
||||
}
|
||||
else if (is_ascii_copyable(data[i]))
|
||||
{
|
||||
run = find_ascii_copyable_run(data + i, s.size() - i);
|
||||
}
|
||||
if (run != 0)
|
||||
{
|
||||
// emit any bytes still pending in string_buffer first to
|
||||
|
||||
@@ -21910,16 +21910,15 @@ class serializer
|
||||
// for the scan. Without it, text whose characters all have to be
|
||||
// escaped - CJK under ensure_ascii, where every byte is >= 0x80 -
|
||||
// runs the scanner once per character only to be told zero.
|
||||
const std::size_t run = [&]() -> std::size_t
|
||||
std::size_t run = 0;
|
||||
if (!EnsureAscii)
|
||||
{
|
||||
if (EnsureAscii)
|
||||
{
|
||||
return is_ascii_copyable(data[i])
|
||||
? find_ascii_copyable_run(data + i, s.size() - i)
|
||||
: 0;
|
||||
}
|
||||
return string_bulk_run(data + i, s.size() - i);
|
||||
}();
|
||||
run = string_bulk_run(data + i, s.size() - i);
|
||||
}
|
||||
else if (is_ascii_copyable(data[i]))
|
||||
{
|
||||
run = find_ascii_copyable_run(data + i, s.size() - i);
|
||||
}
|
||||
if (run != 0)
|
||||
{
|
||||
// emit any bytes still pending in string_buffer first to
|
||||
|
||||
@@ -81,6 +81,44 @@ BENCHMARK_CAPTURE(ParseString, signed_ints, TEST_DATA_DIRECTORY "/regressi
|
||||
BENCHMARK_CAPTURE(ParseString, unsigned_ints, TEST_DATA_DIRECTORY "/regression/unsigned_ints.json");
|
||||
BENCHMARK_CAPTURE(ParseString, small_signed_ints, TEST_DATA_DIRECTORY "/regression/small_signed_ints.json");
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// parse pretty-printed JSON from string
|
||||
//
|
||||
// Every file in the corpus above is minified or only lightly spaced, so none of
|
||||
// them exercise the lexer's whitespace handling. Real-world JSON is frequently
|
||||
// indented - configuration files, pretty-printed API responses, anything kept
|
||||
// under version control - where insignificant whitespace can outweigh the data.
|
||||
// Re-serializing a document with an indentation and parsing that keeps the
|
||||
// content identical to the ParseString row above, so the pair isolates the cost
|
||||
// of the whitespace alone.
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void ParseIndented(benchmark::State& state, const char* filename, int indent)
|
||||
{
|
||||
std::ifstream f(filename);
|
||||
std::string str((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
|
||||
const std::string indented = json::parse(str).dump(indent);
|
||||
|
||||
while (state.KeepRunning())
|
||||
{
|
||||
state.PauseTiming();
|
||||
auto* j = new json();
|
||||
state.ResumeTiming();
|
||||
|
||||
*j = json::parse(indented);
|
||||
|
||||
state.PauseTiming();
|
||||
delete j;
|
||||
state.ResumeTiming();
|
||||
}
|
||||
|
||||
state.SetBytesProcessed(state.iterations() * indented.size());
|
||||
}
|
||||
BENCHMARK_CAPTURE(ParseIndented, jeopardy / 4, TEST_DATA_DIRECTORY "/jeopardy/jeopardy.json", 4);
|
||||
BENCHMARK_CAPTURE(ParseIndented, canada / 4, TEST_DATA_DIRECTORY "/nativejson-benchmark/canada.json", 4);
|
||||
BENCHMARK_CAPTURE(ParseIndented, citm_catalog / 4, TEST_DATA_DIRECTORY "/nativejson-benchmark/citm_catalog.json", 4);
|
||||
BENCHMARK_CAPTURE(ParseIndented, twitter / 4, TEST_DATA_DIRECTORY "/nativejson-benchmark/twitter.json", 4);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// serialize JSON
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user