File: json2msgpack.h

package info (click to toggle)
simdjson 4.2.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 27,936 kB
  • sloc: cpp: 171,612; ansic: 19,122; sh: 1,126; python: 842; makefile: 47; ruby: 25; javascript: 13
file content (48 lines) | stat: -rw-r--r-- 1,232 bytes parent folder | download | duplicates (3)
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
#pragma once

#include "json_benchmark/file_runner.h"

namespace json2msgpack {

using namespace json_benchmark;

template <typename I> struct runner : public file_runner<I> {
  std::string_view result;
  std::unique_ptr<char[]> buffer;

  bool setup(benchmark::State &state) {
    bool isok = this->load_json(state, TWITTER_JSON);
    if (isok) {
      // Let us allocate a sizeable buffer.
      buffer = std::unique_ptr<char[]>(new char[this->json.size() * 4 + 1024]);
    }
    return isok;
  }

  bool before_run(benchmark::State &state) {
    if (!file_runner<I>::before_run(state)) {
      return false;
    }
    // Clear the buffer.
    ::memset(buffer.get(), 0, this->json.size() * 4 + 1024);
    return true;
  }

  bool run(benchmark::State &) {
    return this->implementation.run(this->json, buffer.get(), result);
  }

  template <typename R>
  bool diff(benchmark::State &state, runner<R> &reference) {
    return diff_results(state, result.size(), reference.result.size(), diff_flags::NONE);
  }
};

struct simdjson_ondemand;

template <typename I>
simdjson_inline static void json2msgpack(benchmark::State &state) {
  run_json_benchmark<runner<I>, runner<simdjson_ondemand>>(state);
}

} // namespace json2msgpack