BioPhys-Neural-Agent / src /bin /bench_tps.rs
minseok
๐ŸŒŒ Release BioPhys 6.0 Grand Master: 16GB (14.89GB) Gemma-4 100% Devour, Ecosystem Evolution, Solar MoE, SNN Autoregressive SDK, Dynamic PhaseVM
be99550
Raw
History Blame Contribute Delete
4.48 kB
// โฑ๏ธ ์‹ค์ œ ๋ฌผ๋ฆฌ TPS(Ticks Per Second) ์‹ค์ธก ๋ฒค์น˜๋งˆํฌ (src/bin/bench_tps.rs)
use std::time::Instant;
use rand::Rng;
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum PhaseState {
HyperInhibition,
StandardInhibition,
SubInhibition,
NegQuiescent,
PosQuiescent,
SubExcitation,
StandardExcitation,
HyperExcitation,
}
impl PhaseState {
pub fn value(&self) -> f32 {
match self {
PhaseState::HyperInhibition => -2.0,
PhaseState::StandardInhibition => -1.0,
PhaseState::SubInhibition => -0.5,
PhaseState::NegQuiescent => -0.01,
PhaseState::PosQuiescent => 0.01,
PhaseState::SubExcitation => 0.5,
PhaseState::StandardExcitation => 1.0,
PhaseState::HyperExcitation => 2.0,
}
}
pub fn from_energy(e: f32) -> Self {
if e <= -1.5 { PhaseState::HyperInhibition }
else if e <= -0.75 { PhaseState::StandardInhibition }
else if e <= -0.25 { PhaseState::SubInhibition }
else if e <= 0.0 { PhaseState::NegQuiescent }
else if e <= 0.25 { PhaseState::PosQuiescent }
else if e <= 0.75 { PhaseState::SubExcitation }
else if e <= 1.5 { PhaseState::StandardExcitation }
else { PhaseState::HyperExcitation }
}
}
pub struct BioPhysEngine {
pub size: usize,
pub bedrock: Vec<f32>,
pub topsoil: Vec<PhaseState>,
pub mutation_rate: f32,
}
impl BioPhysEngine {
pub fn new(size: usize, mutation_rate: f32) -> Self {
let mut rng = rand::thread_rng();
let bedrock: Vec<f32> = (0..size * size).map(|_| rng.gen_range(-1.0..1.0)).collect();
let topsoil: Vec<PhaseState> = (0..size * size).map(|_| PhaseState::from_energy(rng.gen_range(-2.0..2.0))).collect();
BioPhysEngine { size, bedrock, topsoil, mutation_rate }
}
#[inline(always)]
pub fn step(&mut self) {
let s = self.size as i32;
let mut next_topsoil = self.topsoil.clone();
for y in 0..s {
for x in 0..s {
let idx = (y * s + x) as usize;
let neighbors = [
((y - 1 + s) % s * s + x) as usize,
((y + 1) % s * s + x) as usize,
(y * s + (x - 1 + s) % s) as usize,
(y * s + (x + 1) % s) as usize,
];
let neighbor_energy = (
self.topsoil[neighbors[0]].value() +
self.topsoil[neighbors[1]].value() +
self.topsoil[neighbors[2]].value() +
self.topsoil[neighbors[3]].value()
) * 0.25;
let local_field = neighbor_energy + self.bedrock[idx];
next_topsoil[idx] = PhaseState::from_energy(local_field);
}
}
self.topsoil = next_topsoil;
}
}
fn main() {
println!("============================================================");
println!(" โšก BioPhys 8-State ์—”์ง„ ์‹ค์ œ ํ•˜๋“œ์›จ์–ด TPS ์‹ค์ธก ๋ฒค์น˜๋งˆํฌ");
println!("============================================================\n");
let grid_size = 16;
let total_ticks = 50_000;
let mut engine = BioPhysEngine::new(grid_size, 0.0);
// ์›Œ๋ฐ์—… (1,000 Ticks)
for _ in 0..1000 {
engine.step();
}
println!("๐Ÿš€ [๋ฒค์น˜๋งˆํฌ ์‹œ์ž‘] 16x16 ๊ฒฉ์ž (256 ๋…ธ๋“œ), ์ด {} Ticks ์—ฐ์‚ฐ ์ค‘...", total_ticks);
let start_time = Instant::now();
for _ in 0..total_ticks {
engine.step();
}
let elapsed = start_time.elapsed();
let elapsed_sec = elapsed.as_secs_f64();
let tps = (total_ticks as f64) / elapsed_sec;
let cell_updates_per_sec = (total_ticks as f64 * (grid_size * grid_size) as f64) / elapsed_sec;
println!("\n============================================================");
println!(" ๐Ÿ“Š ์‹ค์ธก ๋ฒค์น˜๋งˆํฌ ๊ฒฐ๊ณผ (Hardware Measured)");
println!("============================================================");
println!(" โฑ๏ธ ์ด ์†Œ์š” ์‹œ๊ฐ„ : {:.4} ์ดˆ ({:?})", elapsed_sec, elapsed);
println!(" ๐Ÿ”„ ์ด ์‹คํ–‰ ํ‹ฑ(Ticks) : {} Ticks", total_ticks);
println!(" โšก ์‹ค์ œ ๋ฌผ๋ฆฌ TPS : {:.2} Ticks/sec", tps);
println!(" ๐Ÿงฌ ์ดˆ๋‹น ๊ฒฉ์ž ์…€ ๊ฐฑ์‹  : {:.2} MCell/sec (Mega-Updates)", cell_updates_per_sec / 1_000_000.0);
println!("============================================================");
}