<commit_before>//
// Created by <NAME> on 21.01.2016.
//

#include "cppbenchmark.h"

#include <functional>
#include <thread>
#include <vector>

#include "threads/mpsc_ring_queue.h"

const int64_t items_to_produce = 10000000;
const int producers_from = 1;
const int producers_to = 8;
const auto settings = CppBenchmark::Settings().ParamRange(producers_from, producers_to, [](int from, int to, int& result) { int r = result; result *= 2; return r; });

template<typename T, int64_t N, bool BatchMode>
void produce_consume(CppBenchmark::Context& context, const std::function<void()>& wait_strategy)
{
    const int64_t producers_count = context.x();
    int64_t crc = 0;

    // Create multiple producers / single consumer wait-free ring queue
    CppCommon::MPSCRingQueue<T> queue(N, producers_count);

    // Start consumer thread
    auto consumer = std::thread([&queue, &wait_strategy, &crc]()
    {
        for (int64_t i = 0; i < items_to_produce;)
        {
            if (BatchMode)
            {
                // Define the batcher handler
                auto handler = [&crc, &i](const int& item)
                {
                    // Consume the item
                    crc += item;
                
                    // Increase the items counter
                    ++i;
                };
                
                // Dequeue all available items using the given waiting strategy
                while (!queue.Dequeue(handler))
                    wait_strategy();
            }
            else
            {
                // Dequeue using the given waiting strategy
                T item;
                while (!queue.Dequeue(item))
                    wait_strategy();
                
                // Consume the item
                crc += item;

                // Increase the items counter
                ++i;
            }
        }
    });

    // Start producer threads
    std::vector<std::thread> producers;
    for (int64_t producer = 0; producer < producers_count; ++producer)
    {
        producers.push_back(std::thread([&queue, &wait_strategy, producer, producers_count]()
        {
            int64_t items = (items_to_produce / producers_count);
            for (int64_t i = 0; i < items; ++i)
            {
                // Enqueue using the given waiting strategy
                while (!queue.Enqueue((T)(items * producer + i)))
                    wait_strategy();<commit_msg>Small fixes<commit_after>//
// Created by <NAME> on 21.01.2016.
//

#include "cppbenchmark.h"

#include <functional>
#include <thread>
#include <vector>

#include "threads/mpsc_ring_queue.h"

const int64_t items_to_produce = 10000000;
const int producers_from = 1;
const int producers_to = 8;
const auto settings = CppBenchmark::Settings().ParamRange(producers_from, producers_to, [](int from, int to, int& result) { int r = result; result *= 2; return r; });

template<typename T, int64_t N, bool BatchMode>
void produce_consume(CppBenchmark::Context& context, const std::function<void()>& wait_strategy)
{
    const int64_t producers_count = context.x();
    int64_t crc = 0;

    // Create multiple producers / single consumer wait-free ring queue
    CppCommon::MPSCRingQueue<T> queue(N, producers_count);

    // Start consumer thread
    auto consumer = std::thread([&queue, &wait_strategy, &crc]()
    {
        for (int64_t i = 0; i < items_to_produce;)
        {
            if (BatchMode)
            {
                // Define the batcher handler
                auto handler = [&crc, &i](const int& item)
                {
                    // Consume the item
                    crc += item;

                    // Increase the items counter
                    ++i;
                };

                // Dequeue all available items using the given waiting strategy
                while (!queue.Dequeue(handler))
                    wait_strategy();
            }
            else
            {
                // Dequeue using the given waiting strategy
                T item;
                while (!queue.Dequeue(item))
                    wait_strategy();

                // Consume the item
                crc += item;

                // Increase the items counter
                ++i;
            }
        }
    });

    // Start producer threads
    std::vector<std::thread> producers;
    for (int64_t producer = 0; producer < producers_count; ++producer)
    {
        producers.push_back(std::thread([&queue, &wait_strategy, producer, producers_count]()
        {
            int64_t items = (items_to_produce / producers_count);
            for (int64_t i = 0; i < items; ++i)
            {
                // Enqueue using the given waiting strategy
                while (!queue.Enqueue((T)(items * producer + i)))
                    wait_strategy();
{'fraction_non_alphanumeric': 0.1056338028169014, 'fraction_numerical': 0.01615575807787904, 'mean_word_length': 1.7098765432098766, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '4801548', 'n_tokens_mistral': 1448, 'n_tokens_neox': 1315, 'n_words': 368}