#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(target_arch = "wasm32"))]
use criterion::{criterion_group, criterion_main, Criterion};
#[cfg(not(target_arch = "wasm32"))]
use rust_widgets::core::*;
#[cfg(not(target_arch = "wasm32"))]
use rust_widgets::render::*;
#[cfg(not(target_arch = "wasm32"))]
fn bench_fill_pixels(c: &mut Criterion) {
let mut pixels = vec![0u8; 1920 * 1080 * 4];
let color = Color::rgba(128, 64, 32, 255);
c.bench_function("fill_pixels 1080p", |b| b.iter(|| fill_pixels(&mut pixels, color)));
}
#[cfg(not(target_arch = "wasm32"))]
fn bench_blend_pixel(c: &mut Criterion) {
let mut pixels = vec![0u8; 1920 * 1080 * 4];
let color = Color::rgba(128, 64, 32, 128);
c.bench_function("blend_pixel 1080p", |b| {
b.iter(|| blend_pixel(&mut pixels, 1920, 100, 100, color, 0.5))
});
}
#[cfg(not(feature = "mini"))]
#[cfg(not(target_arch = "wasm32"))]
fn bench_render_frame(c: &mut Criterion) {
use rust_widgets::widget::{runtime, Button, Widget};
let geometry = Rect::new(0, 0, 400, 300);
let clear = Color::rgba(0, 0, 0, 0);
c.bench_function("render_frame 400x300", |b| {
b.iter(|| {
let widget: Box<dyn Widget> = Box::new(Button::new("ok".into(), geometry));
let Some(id) = runtime::register(widget) else {
panic!("the runtime must accept a widget");
};
let frame =
runtime::render_frame(id, Size::new(geometry.width, geometry.height), clear);
debug_assert!(frame.is_some(), "a Button must paint a frame");
runtime::unregister(id);
})
});
}
#[cfg(not(feature = "mini"))]
#[cfg(not(target_arch = "wasm32"))]
fn bench_dispatch_pointer_event(c: &mut Criterion) {
use rust_widgets::core::Point;
use rust_widgets::event::Event;
use rust_widgets::widget::base_widgets::label::Label;
use rust_widgets::widget::container_widgets::groupbox::GroupBox;
use rust_widgets::widget::runtime;
use rust_widgets::widget::Widget;
let mut parent = GroupBox::new(Rect::new(0, 0, 400, 300));
let mut child_ids = Vec::new();
for index in 0..8 {
let offsets: i32 = index * 10;
let child = Label::new(format!("c{index}"), Rect::new(offsets, offsets, 60, 40));
let Some(id) = runtime::register(Box::new(child)) else {
panic!("the runtime must accept a child widget");
};
parent.add_child(id);
child_ids.push(id);
}
let Some(root_id) = runtime::register(Box::new(parent)) else {
panic!("the runtime must accept the root widget");
};
let probe_point = Point::new(75, 45);
let probe = Event::MouseMove { pos: probe_point };
c.bench_function("dispatch_pointer_event 9-widget tree", |b| {
b.iter(|| {
let delivered = runtime::dispatch_pointer_event(root_id, &probe, probe_point);
debug_assert!(delivered, "the probe point must reach a widget");
})
});
for id in child_ids {
runtime::unregister(id);
}
runtime::unregister(root_id);
}
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(target_arch = "wasm32"))]
criterion_group!(pixel_benches, bench_fill_pixels, bench_blend_pixel);
#[cfg(not(feature = "mini"))]
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(target_arch = "wasm32"))]
criterion_group!(runtime_benches, bench_render_frame, bench_dispatch_pointer_event);
#[cfg(not(feature = "mini"))]
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(target_arch = "wasm32"))]
criterion_main!(pixel_benches, runtime_benches);
#[cfg(feature = "mini")]
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(target_arch = "wasm32"))]
criterion_main!(pixel_benches);
#[cfg(target_arch = "wasm32")]
fn main() {}