rect_bench/
rect_bench.rs

1// SPDX-License-Identifier: MIT
2
3use orbclient::{Color, EventOption, Renderer, Window};
4
5macro_rules! time {
6    ($msg:tt, $block: block) => ({
7        let _time_instant = ::std::time::Instant::now();
8        $block
9        let _time_duration = _time_instant.elapsed();
10        let _time_fractional = _time_duration.as_secs() as f64
11                             + (_time_duration.subsec_nanos() as f64)/1000000000.0;
12        println!(
13            "{}: {} ms",
14            $msg,
15            _time_fractional * 1000.0
16        );
17    });
18}
19
20fn main() {
21    let mut window = Window::new(10, 10, 800, 600, "RECTANGLE BENCHMARK").unwrap();
22
23    time!("set", { window.set(Color::rgb(255, 255, 255)) });
24
25    time!("rect 400x400", {
26        window.rect(0, 0, 400, 400, Color::rgb(0, 0, 255))
27    });
28
29    time!("rect 200x200", {
30        window.rect(0, 0, 200, 200, Color::rgb(0, 255, 0))
31    });
32
33    time!("rect 100x100", {
34        window.rect(0, 0, 100, 100, Color::rgb(255, 0, 0))
35    });
36
37    time!("sync", {
38        window.sync();
39    });
40
41    'events: loop {
42        for event in window.events() {
43            #[allow(clippy::single_match)]
44            match event.to_option() {
45                EventOption::Quit(_quit_event) => break 'events,
46                _ => (),
47            }
48        }
49    }
50}