gled-ui 2.32.1

gled's egui interface, shared by the desktop app and the browser
Documentation
//! What a frame of the patch editor costs with a large patch, and how much
//! of it goes to telling the draft from the show's patch. Run with
//! `cargo test -p gled-ui patch_editor_frame -- --ignored --nocapture`.

use std::time::{Duration, Instant};

use super::session::Session;

const FRAMES: usize = 40;

fn median(mut times: Vec<Duration>) -> Duration {
    times.sort();
    times[times.len() / 2]
}

#[test]
#[ignore = "a measurement, not a test"]
fn patch_editor_frame_bench() {
    let mut session = Session::with_fixtures(500);
    let frame = median(
        (0..FRAMES)
            .map(|_| {
                let start = Instant::now();
                session.frame(vec![]);
                start.elapsed()
            })
            .collect(),
    );
    // What `FixtureWindow::update` does with the draft each frame besides
    // drawing: the filter (only after the engine's project was adopted),
    // the status for the toolbar and the one after.
    let draft = session.draft();
    let replaced = std::hint::black_box(false);
    let checks = median(
        (0..FRAMES)
            .map(|_| {
                let start = Instant::now();
                std::hint::black_box(!replaced || draft.applied == session.project().patch);
                std::hint::black_box(draft.status());
                std::hint::black_box(draft.status());
                start.elapsed()
            })
            .collect(),
    );
    println!("patch editor, 502 fixtures (median): frame {frame:?}, draft checks {checks:?}");
}