#pragma once #include "json_benchmark/string_runner.h" #include #include namespace large_amazon_cellphones { static const simdjson::padded_string &get_built_json(); using namespace json_benchmark; struct brand { double cumulative_rating; uint64_t reviews_count; simdjson_really_inline bool operator==(const brand &other) const { return cumulative_rating == other.cumulative_rating && reviews_count == other.reviews_count; } simdjson_really_inline bool operator!=(const brand &other) const { return !(*this == other); } }; simdjson_unused static std::ostream &operator<<(std::ostream &o, const brand &b) { o << "cumulative_rating: " << b.cumulative_rating << std::endl; o << "reviews_count: " << b.reviews_count << std::endl; return o; } template simdjson_unused static std::ostream &operator<<(std::ostream &o, const std::pair &p) { o << "brand: " << p.first << std::endl; o << p.second; return o; } template struct runner : public string_runner { std::map result{}; runner() : string_runner(get_built_json()) {} bool before_run(benchmark::State &state) { if (!string_runner::before_run(state)) { return false; } result.clear(); return true; } bool run(benchmark::State &) { return this->implementation.run(this->json, result); } template bool diff(benchmark::State &state, runner &reference) { return diff_results(state, result, reference.result, diff_flags::NONE); } size_t items_per_iteration() { return result.size(); } }; static std::string build_json(size_t N) { std::ifstream in(AMAZON_CELLPHONES_NDJSON); std::string answer((std::istreambuf_iterator(in)), std::istreambuf_iterator()); // Find position of first line to exclude it in further copies size_t first_line = answer.find('\n'); std::string copy(answer,first_line + 1); size_t count{1}; while (answer.size() < N) { answer.append(copy); count++; } std::cout << "Creating a source file spanning " << (answer.size() + 512) / (1024*1024) << " MB (" << count << " copies of original file)" << std::endl; return answer; } static const simdjson::padded_string &get_built_json() { static simdjson::padded_string json = build_json(10*1024*1024); return json; } struct simdjson_dom; template simdjson_really_inline static void large_amazon_cellphones(benchmark::State &state) { run_json_benchmark, runner>(state); } } // namespace large_amazon_cellphones