78 lines
3.1 KiB
C++
78 lines
3.1 KiB
C++
#include "evo/simulation/spatial.hpp"
|
|
|
|
#include <array>
|
|
#include <chrono>
|
|
#include <iostream>
|
|
#include <stdexcept>
|
|
|
|
int main() try {
|
|
constexpr std::uint64_t seed = 123456;
|
|
std::cout << "{\"benchmark\":\"spatial_scan\",\"seed\":" << seed
|
|
<< ",\"queries\":128,\"compiler\":\""
|
|
#if defined(__clang__)
|
|
<< "Clang " << __clang_version__
|
|
#elif defined(_MSC_VER)
|
|
<< "MSVC " << _MSC_VER
|
|
#else
|
|
<< "GCC " << __VERSION__
|
|
#endif
|
|
<< "\",\"build\":\""
|
|
#if defined(NDEBUG)
|
|
<< "release"
|
|
#else
|
|
<< "debug"
|
|
#endif
|
|
<< "\"}\n";
|
|
for (const auto count : {1'000U, 10'000U, 100'000U}) {
|
|
for (const auto clustered : {false, true}) {
|
|
evo::SimulationWorld world{seed};
|
|
evo::Random random{seed};
|
|
const auto coordinate = [&] {
|
|
return evo::Millimetres{
|
|
static_cast<std::uint32_t>(random.next() % (clustered ? 32U : 1024U))};
|
|
};
|
|
for (std::uint32_t index = 0; index < count; ++index) {
|
|
if (!world.create_entity({coordinate(), coordinate()})) {
|
|
throw std::runtime_error("benchmark setup failed");
|
|
}
|
|
}
|
|
std::array<evo::Position2, 128> centers{};
|
|
for (auto& center : centers) {
|
|
center = {coordinate(), coordinate()};
|
|
}
|
|
for (const auto radius : {0U, 16U, 128U, 725U}) {
|
|
for (int sample = -1; sample < 3; ++sample) {
|
|
std::uint64_t hash = 14695981039346656037ULL;
|
|
std::uint64_t matches{};
|
|
const auto start = std::chrono::steady_clock::now();
|
|
for (const auto center : centers) {
|
|
const auto found =
|
|
evo::query_neighbors(world, center, evo::Millimetres{radius});
|
|
if (!found) {
|
|
throw std::runtime_error("benchmark query failed");
|
|
}
|
|
matches += found->size();
|
|
hash = (hash ^ found->size()) * 1099511628211ULL;
|
|
for (const auto id : *found) {
|
|
hash = (hash ^ id.value) * 1099511628211ULL;
|
|
}
|
|
}
|
|
const auto elapsed = std::chrono::duration<double, std::milli>(
|
|
std::chrono::steady_clock::now() - start)
|
|
.count();
|
|
if (sample >= 0) {
|
|
std::cout << "{\"entities\":" << count
|
|
<< ",\"clustered\":" << (clustered ? "true" : "false")
|
|
<< ",\"radius_mm\":" << radius << ",\"sample\":" << sample
|
|
<< ",\"milliseconds\":" << elapsed << ",\"matches\":" << matches
|
|
<< ",\"checksum\":\"" << std::hex << hash << std::dec << "\"}\n";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return 0;
|
|
} catch (...) {
|
|
return 1;
|
|
}
|