From 4b5f44524cc522926f3600be89535f65e6d15c03 Mon Sep 17 00:00:00 2001 From: Andy Killorin <37423245+Speedy6451@users.noreply.github.com> Date: Sun, 29 Oct 2023 11:36:28 -0500 Subject: [PATCH] added benchmark (12us per frame) --- src/main.rs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5eb72c7..2fb7cee 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +#![feature(test)] + use std::collections::hash_map::DefaultHasher; use std::hash::Hash; use std::hash::Hasher; @@ -37,14 +39,11 @@ fn main() -> Result<()> { }; if !last_hash.replace(hash).is_some_and(|h| h == hash) { tray.set_icon(IconSource::Data{data: buffer, height: RES, width: RES})?; - println!("wrote"); - } else { - println!("abstained"); } } } -const RES: i32 = 64; +const RES: i32 = 32; const LEN: usize = (RES*RES) as usize; fn gen_icon( @@ -83,7 +82,7 @@ fn icon_cs( let offset = theta - progress * std::f32::consts::TAU; - if offset < 0.0 && 0.6 < radius && radius < 0.8 { + if offset < 0.0 && 0.5 < radius && radius < 1.0 { pix[1] = if playing {255} else {0}; pix[2] = if playing {0} else {95}; pix[3] = 0; @@ -97,3 +96,18 @@ fn icon_cs( pix[3] = 0; } } + +extern crate test; + +#[cfg(test)] +mod tests { + use super::*; + use test::Bencher; + + use crate::gen_icon; + + #[bench] + fn generate_icon(b: &mut Bencher) { + b.iter(|| gen_icon(0.5, true)); + } +}