File: simdjson_ondemand.h

package info (click to toggle)
simdjson 4.3.1-5
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 31,396 kB
  • sloc: cpp: 195,760; ansic: 20,954; sh: 1,126; python: 885; makefile: 47; ruby: 25; javascript: 13
file content (51 lines) | stat: -rw-r--r-- 1,452 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#pragma once

#if SIMDJSON_EXCEPTIONS

#include "large_random.h"

namespace large_random {

using namespace simdjson;

struct simdjson_ondemand {
  static constexpr diff_flags DiffFlags = diff_flags::NONE;

  ondemand::parser parser{};

  bool run(simdjson::padded_string &json, std::vector<point> &result) {
    auto doc = parser.iterate(json);
    for (ondemand::object coord : doc) {
      result.emplace_back(json_benchmark::point{coord.find_field("x"), coord.find_field("y"), coord.find_field("z")});
    }
    return true;
  }
};

BENCHMARK_TEMPLATE(large_random, simdjson_ondemand)->UseManualTime();
#if SIMDJSON_STATIC_REFLECTION

struct simdjson_ondemand_static_reflect {
  static constexpr diff_flags DiffFlags = diff_flags::NONE;

  ondemand::parser parser{};

  bool run(simdjson::padded_string &json, std::vector<point> &result) {
    auto doc = parser.iterate(json);
    if(auto e = doc.get_array().get<std::vector<point>>(result); e) { return false; }
    // We can also do it like so:
    //for (ondemand::object coord : doc) {
    //  result.emplace_back(coord.get<point>());
    //}
    // It seems that doing the reflection is slower than doing the manual lookup.
    // E.g., it is faster if we do result.emplace_back(coord["x"], coord["y"], coord["z"]);
    return true;
  }
};
BENCHMARK_TEMPLATE(large_random, simdjson_ondemand_static_reflect)->UseManualTime();


#endif
} // namespace large_random

#endif // SIMDJSON_EXCEPTIONS