<commit_before>#include <iostream>
#include <cstddef>
#include <cstdint>
#include <chrono>
#include <iterator>
#include <gtest/gtest.h>
#include <entt/entity/registry.hpp>

struct position {
    std::uint64_t x;
    std::uint64_t y;
};

struct velocity {
    std::uint64_t x;
    std::uint64_t y;
};

template<std::size_t>
struct comp { int x; };

struct timer final {
    timer(): start{std::chrono::system_clock::now()} {}

    void elapsed() {
        auto now = std::chrono::system_clock::now();
        std::cout << std::chrono::duration<double>(now - start).count() << " seconds" << std::endl;
    }

private:
    std::chrono::time_point<std::chrono::system_clock> start;
};

template<typename Func>
void pathological(Func func) {
    entt::registry registry;

    for(std::uint64_t i = 0; i < 500000L; i++) {
        const auto entity = registry.create();
        registry.assign<position>(entity);
        registry.assign<velocity>(entity);
        registry.assign<comp<0>>(entity);
    }

    for(auto i = 0; i < 10; ++i) {
        registry.each([i, &registry](const auto entity) mutable {
            if(!(i % 7)) { registry.remove<position>(entity); }
            if(!(i % 11)) { registry.remove<velocity>(entity); }
            if(!(i % 13)) { registry.remove<comp<0>>(entity); }
            if(!(i % 17)) { registry.destroy(entity); }
        });

        for(std::uint64_t j = 0; j < 50000L; j++) {
            const auto entity = registry.create();
            registry.assign<position>(entity);
            registry.assign<velocity>(entity);
            registry.assign<comp<0>>(entity);
        }
    }

    func(registry, [](auto &... comp) {
        ((comp.x = {}), ...);
    });
}

TEST(Benchmark, Construct) {
    entt::registry registry;

    std::cout << "Constructing 1000000 entities" << std::endl;

    timer timer;

    for(std::uint64_t i = 0; i < 1000000L; i++) {<commit_msg>fixed benchmark (thanks to Kerndog73)<commit_after>#include <iostream>
#include <cstddef>
#include <cstdint>
#include <chrono>
#include <iterator>
#include <gtest/gtest.h>
#include <entt/entity/registry.hpp>

struct position {
    std::uint64_t x;
    std::uint64_t y;
};

struct velocity {
    std::uint64_t x;
    std::uint64_t y;
};

template<std::size_t>
struct comp { int x; };

struct timer final {
    timer(): start{std::chrono::system_clock::now()} {}

    void elapsed() {
        auto now = std::chrono::system_clock::now();
        std::cout << std::chrono::duration<double>(now - start).count() << " seconds" << std::endl;
    }

private:
    std::chrono::time_point<std::chrono::system_clock> start;
};

template<typename Func>
void pathological(Func func) {
    entt::registry registry;

    for(std::uint64_t i = 0; i < 500000L; i++) {
        const auto entity = registry.create();
        registry.assign<position>(entity);
        registry.assign<velocity>(entity);
        registry.assign<comp<0>>(entity);
    }

    for(auto i = 0; i < 10; ++i) {
        registry.each([i = 0, &registry](const auto entity) mutable {
            if(!(++i % 7)) { registry.reset<position>(entity); }
            if(!(++i % 11)) { registry.reset<velocity>(entity); }
            if(!(++i % 13)) { registry.reset<comp<0>>(entity); }
            if(!(++i % 17)) { registry.destroy(entity); }
        });

        for(std::uint64_t j = 0; j < 50000L; j++) {
            const auto entity = registry.create();
            registry.assign<position>(entity);
            registry.assign<velocity>(entity);
            registry.assign<comp<0>>(entity);
        }
    }

    func(registry, [](auto &... comp) {
        ((comp.x = {}), ...);
    });
}

TEST(Benchmark, Construct) {
    entt::registry registry;

    std::cout << "Constructing 1000000 entities" << std::endl;

    timer timer;

    for(std::uint64_t i = 0; i < 1000000L; i++) {
{'fraction_non_alphanumeric': 0.18094246290028637, 'fraction_numerical': 0.02941942202551419, 'mean_word_length': 2.9244126659856997, 'pattern_counts': {'":': 0, '<': 77, '<?xml version=': 0, '>': 49, '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': '5804570', 'n_tokens_mistral': 1372, 'n_tokens_neox': 1256, 'n_words': 257}