82 lines
2.6 KiB
C++
82 lines
2.6 KiB
C++
#include <benchmark/benchmark.h>
|
|
#include <pokemon_battle_sim.h>
|
|
|
|
// Benchmark for battle simulation performance
|
|
static void BM_BattleSimulation(benchmark::State& state) {
|
|
// Set up Pokemon for the benchmark
|
|
PokEng::Pokemon pikachu("Pikachu", 100);
|
|
PokEng::Pokemon charizard("Charizard", 150);
|
|
|
|
// Run the benchmark
|
|
for (auto _ : state) {
|
|
// Simulate a battle between the two Pokemon
|
|
PokEng::simulateBattle(pikachu, charizard);
|
|
|
|
// Reset health for next iteration
|
|
pikachu.setHealth(100);
|
|
charizard.setHealth(150);
|
|
}
|
|
}
|
|
|
|
// Register the benchmark with different configurations
|
|
BENCHMARK(BM_BattleSimulation)
|
|
->Unit(benchmark::kMicrosecond) // Measure in microseconds
|
|
->Iterations(1000) // Run 1000 iterations
|
|
->Repetitions(3); // Repeat the benchmark 3 times for statistical analysis
|
|
|
|
// Benchmark with varying Pokemon health values
|
|
static void BM_BattleSimulationWithHealth(benchmark::State& state) {
|
|
int health = static_cast<int>(state.range(0));
|
|
|
|
PokEng::Pokemon pokemon1("Pokemon1", health);
|
|
PokEng::Pokemon pokemon2("Pokemon2", health);
|
|
|
|
for (auto _ : state) {
|
|
PokEng::simulateBattle(pokemon1, pokemon2);
|
|
|
|
// Reset health
|
|
pokemon1.setHealth(health);
|
|
pokemon2.setHealth(health);
|
|
}
|
|
}
|
|
|
|
// Register benchmark with different health values
|
|
BENCHMARK(BM_BattleSimulationWithHealth)
|
|
->Arg(50) // Test with 50 HP
|
|
->Arg(100) // Test with 100 HP
|
|
->Arg(200) // Test with 200 HP
|
|
->Unit(benchmark::kMicrosecond);
|
|
|
|
// Benchmark for multiple battle simulations
|
|
static void BM_MultipleBattles(benchmark::State& state) {
|
|
int numBattles = static_cast<int>(state.range(0));
|
|
|
|
std::vector<PokEng::Pokemon> team1;
|
|
std::vector<PokEng::Pokemon> team2;
|
|
|
|
// Create teams of Pokemon
|
|
for (int i = 0; i < numBattles; ++i) {
|
|
team1.emplace_back("Pikachu" + std::to_string(i), 100);
|
|
team2.emplace_back("Charizard" + std::to_string(i), 150);
|
|
}
|
|
|
|
for (auto _ : state) {
|
|
// Simulate multiple battles
|
|
for (int i = 0; i < numBattles; ++i) {
|
|
PokEng::simulateBattle(team1[static_cast<size_t>(i)], team2[static_cast<size_t>(i)]);
|
|
}
|
|
|
|
// Reset all Pokemon health
|
|
for (int i = 0; i < numBattles; ++i) {
|
|
team1[static_cast<size_t>(i)].setHealth(100);
|
|
team2[static_cast<size_t>(i)].setHealth(150);
|
|
}
|
|
}
|
|
}
|
|
|
|
BENCHMARK(BM_MultipleBattles)
|
|
->Arg(10) // Test with 10 battles
|
|
->Arg(50) // Test with 50 battles
|
|
->Arg(100) // Test with 100 battles
|
|
->Unit(benchmark::kMillisecond);
|