mirror of
https://github.com/nlohmann/json.git
synced 2026-09-02 22:47:14 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d479d34677 | ||
|
|
09ae666612 | ||
|
|
78f71358c1 | ||
|
|
f707a2f997 | ||
|
|
3426a41391 |
@@ -850,15 +850,16 @@ class serializer
|
|||||||
// for the scan. Without it, text whose characters all have to be
|
// for the scan. Without it, text whose characters all have to be
|
||||||
// escaped - CJK under ensure_ascii, where every byte is >= 0x80 -
|
// escaped - CJK under ensure_ascii, where every byte is >= 0x80 -
|
||||||
// runs the scanner once per character only to be told zero.
|
// runs the scanner once per character only to be told zero.
|
||||||
std::size_t run = 0;
|
const std::size_t run = [&]() -> std::size_t
|
||||||
if (!EnsureAscii)
|
|
||||||
{
|
{
|
||||||
run = string_bulk_run(data + i, s.size() - i);
|
if (EnsureAscii)
|
||||||
}
|
{
|
||||||
else if (is_ascii_copyable(data[i]))
|
return is_ascii_copyable(data[i])
|
||||||
{
|
? find_ascii_copyable_run(data + i, s.size() - i)
|
||||||
run = find_ascii_copyable_run(data + i, s.size() - i);
|
: 0;
|
||||||
}
|
}
|
||||||
|
return string_bulk_run(data + i, s.size() - i);
|
||||||
|
}();
|
||||||
if (run != 0)
|
if (run != 0)
|
||||||
{
|
{
|
||||||
// emit any bytes still pending in string_buffer first to
|
// emit any bytes still pending in string_buffer first to
|
||||||
|
|||||||
@@ -21910,15 +21910,16 @@ class serializer
|
|||||||
// for the scan. Without it, text whose characters all have to be
|
// for the scan. Without it, text whose characters all have to be
|
||||||
// escaped - CJK under ensure_ascii, where every byte is >= 0x80 -
|
// escaped - CJK under ensure_ascii, where every byte is >= 0x80 -
|
||||||
// runs the scanner once per character only to be told zero.
|
// runs the scanner once per character only to be told zero.
|
||||||
std::size_t run = 0;
|
const std::size_t run = [&]() -> std::size_t
|
||||||
if (!EnsureAscii)
|
|
||||||
{
|
{
|
||||||
run = string_bulk_run(data + i, s.size() - i);
|
if (EnsureAscii)
|
||||||
}
|
{
|
||||||
else if (is_ascii_copyable(data[i]))
|
return is_ascii_copyable(data[i])
|
||||||
{
|
? find_ascii_copyable_run(data + i, s.size() - i)
|
||||||
run = find_ascii_copyable_run(data + i, s.size() - i);
|
: 0;
|
||||||
}
|
}
|
||||||
|
return string_bulk_run(data + i, s.size() - i);
|
||||||
|
}();
|
||||||
if (run != 0)
|
if (run != 0)
|
||||||
{
|
{
|
||||||
// emit any bytes still pending in string_buffer first to
|
// emit any bytes still pending in string_buffer first to
|
||||||
|
|||||||
@@ -81,44 +81,6 @@ BENCHMARK_CAPTURE(ParseString, signed_ints, TEST_DATA_DIRECTORY "/regressi
|
|||||||
BENCHMARK_CAPTURE(ParseString, unsigned_ints, TEST_DATA_DIRECTORY "/regression/unsigned_ints.json");
|
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");
|
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
|
// serialize JSON
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
Reference in New Issue
Block a user