Files
FCES-native/benchmarks/bench_evolve.cpp
AI-anonymous 9bbe253810 feat: scaffold FCES-native C++ project with libtorch integration
- CMakeLists.txt with libtorch, GoogleTest, GoogleBenchmark, OpenMP, pybind11
- Header files: config, controller, population, fitness, evolution, spectral, oscillation, telemetry, optimizer
- Source implementations: controller (full micro-MLP forward pass, mutation, crossover), fitness (Welford's algorithm), oscillation (DFT), spectral (SVD rank), optimizer (sign-SGD stub)
- Tests: controller, population, fitness, optimizer (Google Test)
- Benchmarks: evolve throughput, optimizer step (Google Benchmark)
- Examples: simple optimization, PyTorch/libtorch integration
- Python extension: pybind11 bindings with setup.py
- README with architecture diagram and build instructions
2026-05-19 16:05:15 +02:00

46 lines
1.2 KiB
C++

#include <benchmark/benchmark.h>
#include "fces/population.hpp"
#include "fces/controller.hpp"
using namespace fces;
static void BM_ControllerDecideUpdate(benchmark::State& state) {
FuzzyController ctrl;
std::vector<std::vector<float>> stats(state.range(0), {0.1f, 0.2f, 0.3f, 0.4f, 0.5f});
for (auto _ : state) {
auto actions = ctrl.decide_update(stats, 0.0f, 0.5f, 0.0f, 0.1f, 0.0f, 0.0f, 1.0f, 0.0f);
benchmark::DoNotOptimize(actions);
}
}
BENCHMARK(BM_ControllerDecideUpdate)->Arg(10)->Arg(50)->Arg(200);
static void BM_Evolve(benchmark::State& state) {
Population pop(state.range(0));
for (auto _ : state) {
pop.evolve(2.0f, -0.01f, 0.5f);
}
}
BENCHMARK(BM_Evolve)->Arg(50)->Arg(100)->Arg(200);
static void BM_Mutation(benchmark::State& state) {
FuzzyController ctrl;
for (auto _ : state) {
auto child = ctrl.mutate(2.0f, 1.0f);
benchmark::DoNotOptimize(child);
}
}
BENCHMARK(BM_Mutation);
static void BM_Crossover(benchmark::State& state) {
FuzzyController a, b;
for (auto _ : state) {
auto child = a.crossover(b);
benchmark::DoNotOptimize(child);
}
}
BENCHMARK(BM_Crossover);