File: file_runner.h

package info (click to toggle)
simdjson 4.3.1-4
  • 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 (48 lines) | stat: -rw-r--r-- 1,510 bytes parent folder | download | duplicates (7)
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/runner_base.h"
#include "simdjson.h"

namespace json_benchmark {

template<typename I>
struct file_runner : public runner_base<I> {
  simdjson::padded_string original_json{};
  simdjson::padded_string json{};

  simdjson_warn_unused bool load_json(benchmark::State &state, const char *file) {
    simdjson::error_code error;
    if ((error = simdjson::padded_string::load(file).get(original_json))) {
      std::stringstream err;
      err << "error loading " << file << ": " << error;
      state.SkipWithError(err.str().data());
      return false;
    }
    json = simdjson::padded_string(original_json.data(), original_json.size());
    return true;
  }

  simdjson_warn_unused bool before_run(benchmark::State &state) {
    if (!runner_base<I>::after_run(state)) { return false; };
    // Copy the original JSON in case we did *in situ* last time
    std::memcpy(json.data(), original_json.data(), original_json.size());
    return true;
  }

  /** Get the total number of bytes processed in each iteration. Used for metrics like bytes/second. */
  size_t bytes_per_iteration() {
    return json.size();
  }

  /** Get the total number of documents processed in each iteration. Used for metrics like documents/second. */
  size_t documents_per_iteration() {
    return 1;
  }

  /** Get the total number of items processed in each iteration. Used for metrics like items/second. */
  size_t items_per_iteration() {
    return 1;
  }
};

} // namespace json_benchmark