Repository: apache/arrow
File: cpp/src/parquet/arrow/reader_writer_benchmark.cc (C++)

Code before:
struct Examples {
  static constexpr std::array<T, 2> values() { return {127, 128}; }
};

template <>
struct Examples<bool> {
  static constexpr std::array<bool, 2> values() { return {false, true}; }
};

static void BenchmarkReadTable(::benchmark::State& state, const Table& table,
                               std::shared_ptr<WriterProperties> properties,
                               int64_t num_values = -1, int64_t total_bytes = -1) {
  // Make sure we roundtrip Arrow types by storing the schema
  auto arrow_properties = ArrowWriterProperties::Builder().store_schema()->build();
  auto output = CreateOutputStream();
  EXIT_NOT_OK(WriteTable(table, ::arrow::default_memory_pool(), output,
                         /*chunk_size=*/table.num_rows(), properties, arrow_properties));
  PARQUET_ASSIGN_OR_THROW(auto buffer, output->Finish());

  for (auto _ : state) {
    auto reader =
        ParquetFileReader::Open(std::make_shared<::arrow::io::BufferReader>(buffer));
    auto arrow_reader_result =
        FileReader::Make(::arrow::default_memory_pool(), std::move(reader));
    EXIT_NOT_OK(arrow_reader_result.status());
    std::shared_ptr<FileReader> arrow_reader = std::move(*arrow_reader_result);

    std::shared_ptr<Table> table;
    EXIT_NOT_OK(arrow_reader->ReadTable(&table));
  }

  if (num_values == -1) {
    num_values = table.num_rows();
  }
  state.SetItemsProcessed(num_values * state.iterations());
  if (total_bytes != -1) {
    state.SetBytesProcessed(total_bytes * state.iterations());
  }
}

static void BenchmarkReadTable(::benchmark::State& state, const Table& table,
                               int64_t num_values = -1, int64_t total_bytes = -1) {
  BenchmarkReadTable(state, table, default_writer_properties(), num_values, total_bytes);
}

static void BenchmarkReadArray(::benchmark::State& state,
                               const std::shared_ptr<Array>& array, bool nullable,
                               std::shared_ptr<WriterProperties> properties,
                               int64_t num_values = -1, int64_t total_bytes = -1) {
  auto schema = ::arrow::schema({field("s", array->type(), nullable)});
  auto table = Table::Make(schema, {array}, array->length());

Review comment (suggestion):
```suggestion
    auto arrow_reader = std::move(*arrow_reader_result);
```

Code after:
struct Examples {
  static constexpr std::array<T, 2> values() { return {127, 128}; }
};

template <>
struct Examples<bool> {
  static constexpr std::array<bool, 2> values() { return {false, true}; }
};

static void BenchmarkReadTable(::benchmark::State& state, const Table& table,
                               std::shared_ptr<WriterProperties> properties,
                               int64_t num_values = -1, int64_t total_bytes = -1) {
  // Make sure we roundtrip Arrow types by storing the schema
  auto arrow_properties = ArrowWriterProperties::Builder().store_schema()->build();
  auto output = CreateOutputStream();
  EXIT_NOT_OK(WriteTable(table, ::arrow::default_memory_pool(), output,
                         /*chunk_size=*/table.num_rows(), properties, arrow_properties));
  PARQUET_ASSIGN_OR_THROW(auto buffer, output->Finish());

  for (auto _ : state) {
    auto reader =
        ParquetFileReader::Open(std::make_shared<::arrow::io::BufferReader>(buffer));
    auto arrow_reader_result =
        FileReader::Make(::arrow::default_memory_pool(), std::move(reader));
    EXIT_NOT_OK(arrow_reader_result.status());
    auto arrow_reader = std::move(*arrow_reader_result);

    std::shared_ptr<Table> table;
    EXIT_NOT_OK(arrow_reader->ReadTable(&table));
  }

  if (num_values == -1) {
    num_values = table.num_rows();
  }
  state.SetItemsProcessed(num_values * state.iterations());
  if (total_bytes != -1) {
    state.SetBytesProcessed(total_bytes * state.iterations());
  }
}

static void BenchmarkReadTable(::benchmark::State& state, const Table& table,
                               int64_t num_values = -1, int64_t total_bytes = -1) {
  BenchmarkReadTable(state, table, default_writer_properties(), num_values, total_bytes);
}

static void BenchmarkReadArray(::benchmark::State& state,
                               const std::shared_ptr<Array>& array, bool nullable,
                               std::shared_ptr<WriterProperties> properties,
                               int64_t num_values = -1, int64_t total_bytes = -1) {
  auto schema = ::arrow::schema({field("s", array->type(), nullable)});
  auto table = Table::Make(schema, {array}, array->length());