<commit_before>#include <algorithm>
#include <chrono>
#include <fstream>
#include <vector>

#include <CGAL/ch_graham_andrew.h>

#include "point.h"
#include "bsthull.h"

template<class TFn, class ...TArgs>
double measureAlgo(TFn fn, size_t testsNum, TArgs&&... args)
{
   using namespace std::chrono;

   const auto tStart = high_resolution_clock::now();

   for (size_t test = 0; test < testsNum; ++test)
      (void) fn(std::forward<TArgs>(args)...);

   const auto tEnd = high_resolution_clock::now();

   return duration_cast<duration<double>>(tEnd - tStart).count() / testsNum;
}

int main()
{
   std::ifstream fin("in.txt");
   std::ofstream fout("out.txt");

   std::ofstream("algoNames.txt") << "Graham scan\nNew algorithm";

   size_t testsNum;
   fin >> testsNum;

   for (size_t test = 0; test < testsNum; ++test)
   {
      int pointsNum;
      fin >> pointsNum;

      std::vector<Point> points;
      points.reserve(pointsNum);
      for (int i = 0; i < pointsNum; ++i)
      {
         double x, y;
         fin >> x >> y;
         points.emplace_back(x, y);
      }

      const size_t runsNum = std::max(30, 10'000'000 / pointsNum);
      std::vector<Point> result(pointsNum);

      // heat up cache for algo
      measureAlgo(CGAL::ch_graham_andrew<std::vector<Point>::iterator, std::vector<Point>::iterator>,
         runsNum, points.begin(), points.end(), result.begin());
      fout << measureAlgo(CGAL::ch_graham_andrew<std::vector<Point>::iterator, std::vector<Point>::iterator>,
         runsNum, points.begin(), points.end(), result.begin()) << ' ';

      // heat up cache for algo
      measureAlgo(algorithms::BstConvexHull::Create, runsNum, points);
      fout << measureAlgo(algorithms::BstConvexHull::Create, runsNum, points) << '\n';
   }

   return 0;
}<commit_msg>Rewrite measuring of algorithms<commit_after>#include <algorithm>
#include <chrono>
#include <fstream>
#include <vector>
#include <iterator>

#include <CGAL/ch_graham_andrew.h>

#include "point.h"
#include "bsthull.h"

template<class TFn, class ...TArgs>
double measureAlgo(TFn fn, size_t runsExternal, size_t runsInternal)
{
   using namespace std::chrono;

   double bestResult = std::numeric_limits<double>::max();

   for (size_t run = 0; run < runsExternal; ++run)
   {
      const auto tStart = high_resolution_clock::now();
      for (size_t test = 0; test < runsInternal; ++test) fn();
      const auto tEnd = high_resolution_clock::now();
      bestResult = std::min(bestResult, duration_cast<duration<double>>(tEnd - tStart).count() / runsInternal);
   }

   return bestResult;
}

int main()
{
   std::ifstream fin("in.txt");
   std::ofstream fout("out.txt");
   std::ofstream("algoNames.txt") << "Graham scan\nNew algorithm";

   size_t testsNum;
   fin >> testsNum;

   for (size_t test = 0; test < testsNum; ++test)
   {
      int pointsNum;
      fin >> pointsNum;

      std::vector<Point> points;
      points.reserve(pointsNum);
      for (int i = 0; i < pointsNum; ++i)
      {
         double x, y;
         fin >> x >> y;
         points.emplace_back(x, y);
      }

      const size_t runsExternal = 20;
      const size_t runsInternal = std::max(30, 1'000'000 / pointsNum);

      fout << measureAlgo(
            [&points]() {
            std::vector<Point> result;
            result.reserve(points.size());
            CGAL::ch_graham_andrew(points.begin(), points.end(), std::back_inserter(result));
         },
         runsExternal, runsInternal) << ' ';

      fout << measureAlgo(
         [&points]() { algorithms::BstConvexHull::Create(points); },
         runsExternal, runsInternal) << '\n';
   }

   return 0;
}
{'fraction_non_alphanumeric': 0.15669593852908892, 'fraction_numerical': 0.00823271130625686, 'mean_word_length': 3.2334494773519165, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '2589183', 'n_tokens_mistral': 1271, 'n_tokens_neox': 1216, 'n_words': 272}