//! Text pipeline benchmark. //! //! Continuously recomputes a large `Text` component with 100 sections. use bevy::{ diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, prelude::*, text::{BreakLineOn, Text2dBounds}, window::{PresentMode, WindowPlugin}, }; fn main() { App::new() .add_plugins(DefaultPlugins.set(WindowPlugin { primary_window: Some(Window { present_mode: PresentMode::Immediate, ..default() }), ..default() })) .add_plugin(FrameTimeDiagnosticsPlugin::default()) .add_plugin(LogDiagnosticsPlugin::default()) .add_systems(Startup, spawn) .add_systems(Update, update_text_bounds) .run(); } fn spawn(mut commands: Commands, asset_server: Res) { commands.spawn(Camera2dBundle::default()); let sections = (1..=50) .flat_map(|i| { [ TextSection { value: "text".repeat(i), style: TextStyle { font: asset_server.load("fonts/FiraMono-Medium.ttf"), font_size: (4 + i % 10) as f32, color: Color::BLUE, }, }, TextSection { value: "pipeline".repeat(i), style: TextStyle { font: asset_server.load("fonts/FiraSans-Bold.ttf"), font_size: (4 + i % 11) as f32, color: Color::YELLOW, }, }, ] }) .collect::>(); commands.spawn(Text2dBundle { text: Text { sections, alignment: TextAlignment::Center, linebreak_behaviour: BreakLineOn::AnyCharacter, }, ..Default::default() }); } // changing the bounds of the text will cause a recomputation fn update_text_bounds(time: Res