<commit_before>#include <thread>
#include <iostream>

#include <benchmark/benchmark.h>

#include "DiskPool.h"
#include "measure.h"

std::atomic<int> stop{0};

// Write all the data to disk.
void io_thread(DiskPool_mt *memory_pool) {
    using precision = std::chrono::milliseconds;

    printf("Starting IO thread.\n");

    while (!stop.load(std::memory_order_acquire)) {
        sleep(1);

        auto ret = measure<precision>::execution(
            [memory_pool] {
                memory_pool->flush();
                return 0;
            }
        );

        printf("Took %lld ms.\n", ret.second);
    }

    printf("Stopping IO thread.\n");
}

// Check the single thread performance.
DiskPool_st memory_pool_st("/tmp/memory.log", GB(8));
void BM_MemoryAllocation_DiskPool_st(benchmark::State &state, DiskPool_st *pool) {
    while (state.KeepRunning()) {
        auto mem = pool->alloc(sizeof(int));
        benchmark::DoNotOptimize(mem);
    }
}

BENCHMARK_CAPTURE(BM_MemoryAllocation_DiskPool_st, SingleThreaded, &memory_pool_st);

static DiskPool_mt memory_pool_mt("/tmp/memory.log", GB(8));
void BM_MemoryAllocation_DiskPool_mt(benchmark::State &state, DiskPool_mt *pool) {
    DiskPool_st memory_pool("/tmp/memory.log", GB(8));
    while (state.KeepRunning()) {
        auto mem = pool->alloc(sizeof(int));
        benchmark::DoNotOptimize(mem);
    }
}

BENCHMARK_CAPTURE(BM_MemoryAllocation_DiskPool_mt, Threaded, &memory_pool_mt)->ThreadRange(1, 32);

void BM_MemoryAllocation_malloc(benchmark::State &state) {<commit_msg>Fix format string<commit_after>#include <thread>
#include <iostream>

#include <benchmark/benchmark.h>

#include "DiskPool.h"
#include "measure.h"

std::atomic<int> stop{0};

// Write all the data to disk.
void io_thread(DiskPool_mt *memory_pool) {
    using precision = std::chrono::milliseconds;

    printf("Starting IO thread.\n");

    while (!stop.load(std::memory_order_acquire)) {
        sleep(1);

        auto ret = measure<precision>::execution(
            [memory_pool] {
                memory_pool->flush();
                return 0;
            }
        );

        printf("Took %ld ms.\n", ret.second);
    }

    printf("Stopping IO thread.\n");
}

// Check the single thread performance.
DiskPool_st memory_pool_st("/tmp/memory.log", GB(8));
void BM_MemoryAllocation_DiskPool_st(benchmark::State &state, DiskPool_st *pool) {
    while (state.KeepRunning()) {
        auto mem = pool->alloc(sizeof(int));
        benchmark::DoNotOptimize(mem);
    }
}

BENCHMARK_CAPTURE(BM_MemoryAllocation_DiskPool_st, SingleThreaded, &memory_pool_st);

static DiskPool_mt memory_pool_mt("/tmp/memory.log", GB(8));
void BM_MemoryAllocation_DiskPool_mt(benchmark::State &state, DiskPool_mt *pool) {
    DiskPool_st memory_pool("/tmp/memory.log", GB(8));
    while (state.KeepRunning()) {
        auto mem = pool->alloc(sizeof(int));
        benchmark::DoNotOptimize(mem);
    }
}

BENCHMARK_CAPTURE(BM_MemoryAllocation_DiskPool_mt, Threaded, &memory_pool_mt)->ThreadRange(1, 32);

void BM_MemoryAllocation_malloc(benchmark::State &state) {
{'fraction_non_alphanumeric': 0.13947453778786895, 'fraction_numerical': 0.005838469023678235, 'mean_word_length': 3.811232449297972, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 21, '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': '5333560', 'n_tokens_mistral': 1054, 'n_tokens_neox': 1015, 'n_words': 184}