<commit_before>// Pass -DGHEAP_CPP11 to compiler for gheap_cpp11.hpp tests,
// otherwise gheap_cpp03.hpp will be tested.

#include "gheap.hpp"
#include "galgorithm.hpp"
#include "gpriority_queue.hpp"

#include <algorithm>  // for *_heap(), copy(), move()
#include <cstdlib>    // for rand(), srand()
#include <ctime>      // for clock()
#include <iostream>
#include <memory>     // for *_temporary_buffer()
#include <queue>      // for priority_queue
#include <utility>    // for pair, C++11 move()
#include <vector>     // for vector

using namespace std;

namespace {

double get_time()
{
  return (double)clock() / CLOCKS_PER_SEC;
}

void print_performance(const double t, const size_t m)
{
  cout << ": " << (m / t / 1000) << " Kops/s" << endl;
}

template <class T>
void init_array(T *const a, const size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    a[i] = rand();
  }
}

// Dummy wrapper for STL heap.
struct stl_heap
{
  template <class RandomAccessIterator, class LessComparer>
  static void make_heap(const RandomAccessIterator &first,
      const RandomAccessIterator &last, const LessComparer &less_comparer)
  {
    std::make_heap(first, last, less_comparer);
  }

  template <class RandomAccessIterator, class LessComparer>
  static void sort_heap(const RandomAccessIterator &first,
      const RandomAccessIterator &last, const LessComparer &less_comparer)
  {
    std::sort_heap(first, last, less_comparer);
  }
};

// Dummy wrapper for STL algorithms.
struct stl_algorithm
{
  template <class RandomAccessIterator>
  static void partial_sort(const RandomAccessIterator &first,
      const RandomAccessIterator &middle, const RandomAccessIterator &last)
  {
    std::partial_sort(first, middle, last);
  }
};

template <class T, class Heap>
void perftest_heapsort(T *const a, const size_t n, const size_t m)
{
  cout << "perftest_heapsort(n=" << n << ", m=" << m << ")";

  typedef galgorithm<Heap> algorithm;

  double total_time = 0;

  for (size_t i = 0; i < m / n; ++i) {
    init_array(a, n);

    double start = get_time();
    algorithm::heapsort(a, a + n);
    double end = get_time();

    total_time += end - start;
  }

  print_performance(total_time, m);
}

template <class T, class Algorithm>
void perftest_partial_sort(T *const a, const size_t n, const size_t m)
{
  const size_t k = n / 4;

  cout << "perftest_partial_sort(n=" << n << ", m=" << m << ", k=" << k << ")";

  double total_time = 0;

  for (size_t i = 0; i < m / n; ++i) {
    init_array(a, n);

    double start = get_time();
    Algorithm::partial_sort(a, a + k, a + n);
    double end = get_time();

    total_time += end - start;
  }

  print_performance(total_time, m);
}

template <class T>
void move_items(T *const src, const size_t n, T *const dst)
{
#ifdef GHEAP_CPP11
  move(src, src + n, dst);
#else
  copy(src, src + n, dst);
  for (size_t i = 0; i < n; ++i) {
    src[i].~T();
  }
#endif
}

template <class T>
class nway_output_iterator
{
private:
  T *_next;

public:
  nway_output_iterator(T *const next) : _next(next) {}

  nway_output_iterator &operator * () { return *this; }<commit_msg>call destructors after items have been moved to another location in move_items()<commit_after>// Pass -DGHEAP_CPP11 to compiler for gheap_cpp11.hpp tests,
// otherwise gheap_cpp03.hpp will be tested.

#include "gheap.hpp"
#include "galgorithm.hpp"
#include "gpriority_queue.hpp"

#include <algorithm>  // for *_heap(), copy(), move()
#include <cstdlib>    // for rand(), srand()
#include <ctime>      // for clock()
#include <iostream>
#include <memory>     // for *_temporary_buffer()
#include <queue>      // for priority_queue
#include <utility>    // for pair, C++11 move()
#include <vector>     // for vector

using namespace std;

namespace {

double get_time()
{
  return (double)clock() / CLOCKS_PER_SEC;
}

void print_performance(const double t, const size_t m)
{
  cout << ": " << (m / t / 1000) << " Kops/s" << endl;
}

template <class T>
void init_array(T *const a, const size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    a[i] = rand();
  }
}

// Dummy wrapper for STL heap.
struct stl_heap
{
  template <class RandomAccessIterator, class LessComparer>
  static void make_heap(const RandomAccessIterator &first,
      const RandomAccessIterator &last, const LessComparer &less_comparer)
  {
    std::make_heap(first, last, less_comparer);
  }

  template <class RandomAccessIterator, class LessComparer>
  static void sort_heap(const RandomAccessIterator &first,
      const RandomAccessIterator &last, const LessComparer &less_comparer)
  {
    std::sort_heap(first, last, less_comparer);
  }
};

// Dummy wrapper for STL algorithms.
struct stl_algorithm
{
  template <class RandomAccessIterator>
  static void partial_sort(const RandomAccessIterator &first,
      const RandomAccessIterator &middle, const RandomAccessIterator &last)
  {
    std::partial_sort(first, middle, last);
  }
};

template <class T, class Heap>
void perftest_heapsort(T *const a, const size_t n, const size_t m)
{
  cout << "perftest_heapsort(n=" << n << ", m=" << m << ")";

  typedef galgorithm<Heap> algorithm;

  double total_time = 0;

  for (size_t i = 0; i < m / n; ++i) {
    init_array(a, n);

    double start = get_time();
    algorithm::heapsort(a, a + n);
    double end = get_time();

    total_time += end - start;
  }

  print_performance(total_time, m);
}

template <class T, class Algorithm>
void perftest_partial_sort(T *const a, const size_t n, const size_t m)
{
  const size_t k = n / 4;

  cout << "perftest_partial_sort(n=" << n << ", m=" << m << ", k=" << k << ")";

  double total_time = 0;

  for (size_t i = 0; i < m / n; ++i) {
    init_array(a, n);

    double start = get_time();
    Algorithm::partial_sort(a, a + k, a + n);
    double end = get_time();

    total_time += end - start;
  }

  print_performance(total_time, m);
}

template <class T>
void move_items(T *const src, const size_t n, T *const dst)
{
#ifdef GHEAP_CPP11
  move(src, src + n, dst);
#else
  copy(src, src + n, dst);
#endif

  for (size_t i = 0; i < n; ++i) {
    src[i].~T();
  }
}

template <class T>
class nway_output_iterator
{
private:
  T *_next;

public:
  nway_output_iterator(T *const next) : _next(next) {}

  nway_output_iterator &operator * () { return *this; }
{'fraction_non_alphanumeric': 0.14039566049776644, 'fraction_numerical': 0.006700701978302489, 'mean_word_length': 3.674869500372856, 'pattern_counts': {'":': 2, '<': 109, '<?xml version=': 0, '>': 37, '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': '5849075', 'n_tokens_mistral': 2291, 'n_tokens_neox': 2211, 'n_words': 651}