FpsCounter: Use a const instead of generating a new time::Duration each tick

Former-commit-id: e0b6ec4bbc97119f6e82d1219d1406626b50e890
This commit is contained in:
Michel Heily 2020-04-11 16:29:56 +03:00
parent 884f39ca8f
commit 810ff89ea7

View file

@ -66,6 +66,8 @@ pub struct FpsCounter {
timer: time::Instant,
}
const SECOND: time::Duration = time::Duration::from_secs(1);
impl Default for FpsCounter {
fn default() -> FpsCounter {
FpsCounter {
@ -78,7 +80,7 @@ impl Default for FpsCounter {
impl FpsCounter {
pub fn tick(&mut self) -> Option<u32> {
self.count += 1;
if self.timer.elapsed() >= time::Duration::from_secs(1) {
if self.timer.elapsed() >= SECOND {
let fps = self.count;
self.timer = time::Instant::now();
self.count = 0;