<commit_before>/*
    RawSpeed - RAW file decoder.

    Copyright (C) 2017 <NAME>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "RawSpeed-API.h"            // for RawDecoder, FileReader, RawParser
#include <benchmark/benchmark_api.h> // for Initialize, RegisterBenchmark
#include <memory>                    // for unique_ptr
#include <string>                    // for string

using rawspeed::CameraMetaData;
using rawspeed::FileReader;
using rawspeed::RawImage;
using rawspeed::RawParser;

static inline void BM_RawSpeed(benchmark::State& state, const char* fileName) {
#ifdef HAVE_PUGIXML
  static const CameraMetaData metadata(CMAKE_SOURCE_DIR "/data/cameras.xml");
#else
  static const CameraMetaData metadata{};
#endif

  FileReader reader(fileName);
  const auto map(reader.readFile());

  while (state.KeepRunning()) {
    RawParser parser(map.get());
    auto decoder(parser.getDecoder(&metadata));

    decoder->failOnUnknown = false;
    decoder->checkSupport(&metadata);

    decoder->decodeRaw();
    decoder->decodeMetaData(&metadata);
    RawImage raw = decoder->mRaw;

    benchmark::DoNotOptimize(raw);
  }

  std::string label("filesize=");
  label += std::to_string(map->getSize() / (1UL << 10UL));
  label += "KB";
  state.SetLabel(label.c_str());

  state.SetItemsProcessed(state.iterations());
  state.SetBytesProcessed(state.iterations() * map->getSize());
}

int main(int argc, char** argv) {
  benchmark::Initialize(&argc, argv);

  for (int i = 1; i < argc; i++) {
    const char* fName = argv[i];
    auto* b = benchmark::RegisterBenchmark(fName, &BM_RawSpeed, fName);
    b->Unit(benchmark::kMillisecond);
  }

  benchmark::RunSpecifiedBenchmarks();
}<commit_msg>rsbench: specify UseRealTime(), measure wall clock<commit_after>/*
    RawSpeed - RAW file decoder.

    Copyright (C) 2017 <NAME>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "RawSpeed-API.h"            // for RawDecoder, FileReader, RawParser
#include <benchmark/benchmark_api.h> // for Initialize, RegisterBenchmark
#include <memory>                    // for unique_ptr
#include <string>                    // for string

using rawspeed::CameraMetaData;
using rawspeed::FileReader;
using rawspeed::RawImage;
using rawspeed::RawParser;

static inline void BM_RawSpeed(benchmark::State& state, const char* fileName) {
#ifdef HAVE_PUGIXML
  static const CameraMetaData metadata(CMAKE_SOURCE_DIR "/data/cameras.xml");
#else
  static const CameraMetaData metadata{};
#endif

  FileReader reader(fileName);
  const auto map(reader.readFile());

  while (state.KeepRunning()) {
    RawParser parser(map.get());
    auto decoder(parser.getDecoder(&metadata));

    decoder->failOnUnknown = false;
    decoder->checkSupport(&metadata);

    decoder->decodeRaw();
    decoder->decodeMetaData(&metadata);
    RawImage raw = decoder->mRaw;

    benchmark::DoNotOptimize(raw);
  }

  std::string label("filesize=");
  label += std::to_string(map->getSize() / (1UL << 10UL));
  label += "KB";
  state.SetLabel(label.c_str());

  state.SetItemsProcessed(state.iterations());
  state.SetBytesProcessed(state.iterations() * map->getSize());
}

int main(int argc, char** argv) {
  benchmark::Initialize(&argc, argv);

  for (int i = 1; i < argc; i++) {
    const char* fName = argv[i];
    auto* b = benchmark::RegisterBenchmark(fName, &BM_RawSpeed, fName);
    b->Unit(benchmark::kMillisecond);
    b->UseRealTime();
  }

  benchmark::RunSpecifiedBenchmarks();
}
{'fraction_non_alphanumeric': 0.10873586844809867, 'fraction_numerical': 0.008221993833504625, 'mean_word_length': 3.875751503006012, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5692940', 'n_tokens_mistral': 1455, 'n_tokens_neox': 1391, 'n_words': 466}