From b6781adb8858d917d3b6ff0e5fc7642b57d9ca0d Mon Sep 17 00:00:00 2001 From: Dimitri Belopopsky Date: Sun, 15 Oct 2023 13:24:00 +0200 Subject: [PATCH] Add table showing complexity of operations for Input --- crates/bevy_input/src/button_input.rs | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/crates/bevy_input/src/button_input.rs b/crates/bevy_input/src/button_input.rs index 8e4c05e4b9e2a..8dacec26d22db 100644 --- a/crates/bevy_input/src/button_input.rs +++ b/crates/bevy_input/src/button_input.rs @@ -29,6 +29,35 @@ use bevy_ecs::schedule::State; /// * Using [`ButtonInput::clear_just_pressed`] or [`ButtonInput::clear_just_released`] instead. /// * Calling [`ButtonInput::clear`] or [`ButtonInput::reset`] immediately after the state change. /// +/// ## Performance +/// +/// For all operations, the following conventions are used: +/// - **n** is the number of stored inputs. +/// - **m** is the number of input arguments passed to the method. +/// - **\***-suffix denotes an amortized cost. +/// - **~**-suffix denotes an expected cost. +/// +/// See Rust's [std::collections doc on performance](https://doc.rust-lang.org/std/collections/index.html#performance) for more details on the conventions used here. +/// +/// | **[`ButtonInput`] operations** | **Computational complexity** | +/// |-----------------------------------|------------------------------------| +/// | [`ButtonInput::any_just_pressed`] | *O*(m*n) | +/// | [`ButtonInput::any_just_released`] | *O*(m*n) | +/// | [`ButtonInput::any_pressed`] | *O*(m*n) | +/// | [`ButtonInput::get_just_pressed`] | *O*(n) | +/// | [`ButtonInput::get_just_released`] | *O*(n) | +/// | [`ButtonInput::get_pressed`] | *O*(n) | +/// | [`ButtonInput::just_pressed`] | *O*(1)~ | +/// | [`ButtonInput::just_released`] | *O*(1)~ | +/// | [`ButtonInput::pressed`] | *O*(1)~ | +/// | [`ButtonInput::press`] | *O*(1)~* | +/// | [`ButtonInput::release`] | *O*(1)~* | +/// | [`ButtonInput::release_all`] | *O*(n)~* | +/// | [`ButtonInput::clear_just_pressed`] | *O*(1)~ | +/// | [`ButtonInput::clear_just_released`] | *O*(1)~ | +/// | [`ButtonInput::reset_all`] | *O*(n) | +/// | [`ButtonInput::clear`] | *O*(n) | +/// /// ## Note /// /// When adding this resource for a new input type, you should: