//! Testing the difference between not using Flurx and using Flurx in a simple countdown. #![allow(missing_docs)] use bevy::app::{App, Startup}; use bevy::core::TaskPoolPlugin; use bevy::prelude::{Commands, Local, Res, ResMut, Resource, Update}; use criterion::{Criterion, criterion_group, criterion_main}; use bevy_flurx::FlurxPlugin; use bevy_flurx::prelude::{once, Reactor, Then, wait}; #[derive(Resource, Default)] struct Exit(bool); #[derive(Resource, Default)] struct Limit(usize); fn without_flurx(count: usize, c: &mut Criterion) { c.bench_function(&format!("without_flurx count: {count}"), |b| { b.iter(|| { let mut app = App::new(); app .add_plugins(TaskPoolPlugin::default()) .init_resource::() .insert_resource(Limit(count)) .add_systems(Update, move |mut exit: ResMut, mut local: Local, limit: Res| { *local += 1; if *local == limit.0 { exit.0 = true; } }); while !app.world().resource::().0 { app.update(); } }); }); } fn with_flurx(count: usize, c: &mut Criterion) { c.bench_function(&format!("with_flurx count: {count}"), move |b| { b.iter(move || { let mut app = App::new(); app .add_plugins(( TaskPoolPlugin::default(), FlurxPlugin )) .init_resource::() .insert_resource(Limit(count)) .add_systems(Startup, |mut commands: Commands| { commands.spawn(Reactor::schedule(|task| async move { task.will(Update, { wait::until(|mut local: Local, limit: Res| { *local += 1; *local == limit.0 }) .then(once::run(|mut exit: ResMut| { exit.0 = true; })) }).await; })); }); while !app.world().resource::().0 { app.update(); } }); }); } fn cmp_count_10000(c: &mut Criterion) { const COUNT: usize = 10000; without_flurx(COUNT, c); with_flurx(COUNT, c); } criterion_group!(cmp_countup, cmp_count_10000); criterion_main!(cmp_countup);