* feat: update Cargo.toml for 2024 edition and optimize release profiles * feat: refactor environment variable settings for Linux and improve code organization * Refactor conditional statements to use `&&` for improved readability - Updated multiple files to combine nested `if let` statements using `&&` for better clarity and conciseness. - This change enhances the readability of the code by reducing indentation levels and making the conditions more straightforward. - Affected files include: media_unlock_checker.rs, profile.rs, clash.rs, profiles.rs, async_proxy_query.rs, core.rs, handle.rs, hotkey.rs, service.rs, timer.rs, tray/mod.rs, merge.rs, seq.rs, config.rs, proxy.rs, window.rs, general.rs, dirs.rs, i18n.rs, init.rs, network.rs, and window.rs in the resolve module. * refactor: streamline conditional checks using `&&` for improved readability * fix: update release profile settings for panic behavior and optimization * fix: adjust optimization level in Cargo.toml and reorder imports in lightweight.rs
92 lines
2.3 KiB
Rust
92 lines
2.3 KiB
Rust
use criterion::{Criterion, criterion_group, criterion_main};
|
|
use std::hint::black_box;
|
|
|
|
// 业务模型 & Draft
|
|
use app_lib::config::Draft as DraftNew;
|
|
use app_lib::config::IVerge;
|
|
|
|
// fn bench_apply_old(c: &mut Criterion) {
|
|
// c.bench_function("apply_draft_old", |b| {
|
|
// b.iter(|| {
|
|
// let verge = Box::new(IVerge {
|
|
// enable_auto_launch: Some(true),
|
|
// enable_tun_mode: Some(false),
|
|
// ..Default::default()
|
|
// });
|
|
|
|
// let draft = DraftOld::from(black_box(verge));
|
|
|
|
// {
|
|
// let mut d = draft.draft_mut();
|
|
// d.enable_auto_launch = Some(false);
|
|
// }
|
|
|
|
// let _ = draft.apply();
|
|
// });
|
|
// });
|
|
// }
|
|
|
|
// fn bench_discard_old(c: &mut Criterion) {
|
|
// c.bench_function("discard_draft_old", |b| {
|
|
// b.iter(|| {
|
|
// let verge = Box::new(IVerge::default());
|
|
// let draft = DraftOld::from(black_box(verge));
|
|
|
|
// {
|
|
// let mut d = draft.draft_mut();
|
|
// d.enable_auto_launch = Some(false);
|
|
// }
|
|
|
|
// let _ = draft.discard();
|
|
// });
|
|
// });
|
|
// }
|
|
|
|
/// 基准:修改草稿并 apply()
|
|
fn bench_apply_new(c: &mut Criterion) {
|
|
c.bench_function("apply_draft_new", |b| {
|
|
b.iter(|| {
|
|
let verge = Box::new(IVerge {
|
|
enable_auto_launch: Some(true),
|
|
enable_tun_mode: Some(false),
|
|
..Default::default()
|
|
});
|
|
|
|
let draft = DraftNew::from(black_box(verge));
|
|
|
|
{
|
|
let mut d = draft.draft_mut();
|
|
d.enable_auto_launch = Some(false);
|
|
}
|
|
|
|
let _ = draft.apply();
|
|
});
|
|
});
|
|
}
|
|
|
|
/// 基准:修改草稿并 discard()
|
|
fn bench_discard_new(c: &mut Criterion) {
|
|
c.bench_function("discard_draft_new", |b| {
|
|
b.iter(|| {
|
|
let verge = Box::new(IVerge::default());
|
|
let draft = DraftNew::from(black_box(verge));
|
|
|
|
{
|
|
let mut d = draft.draft_mut();
|
|
d.enable_auto_launch = Some(false);
|
|
}
|
|
|
|
let _ = draft.discard();
|
|
});
|
|
});
|
|
}
|
|
|
|
criterion_group!(
|
|
benches,
|
|
// bench_apply_old,
|
|
// bench_discard_old,
|
|
bench_apply_new,
|
|
bench_discard_new
|
|
);
|
|
criterion_main!(benches);
|