cargo fmt

This commit is contained in:
Simon Gardling 2025-12-05 20:29:15 -05:00
parent 07858b229f
commit 5480522ddb
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D
4 changed files with 64 additions and 60 deletions

View File

@ -8,81 +8,81 @@ use criterion::{criterion_group, criterion_main, Criterion};
use pprof::ProfilerGuard; use pprof::ProfilerGuard;
pub struct FlamegraphProfiler<'a> { pub struct FlamegraphProfiler<'a> {
frequency: c_int, frequency: c_int,
active_profiler: Option<ProfilerGuard<'a>>, active_profiler: Option<ProfilerGuard<'a>>,
} }
impl<'a> FlamegraphProfiler<'a> { impl<'a> FlamegraphProfiler<'a> {
#[allow(dead_code)] #[allow(dead_code)]
pub fn new(frequency: c_int) -> Self { pub fn new(frequency: c_int) -> Self {
FlamegraphProfiler { FlamegraphProfiler {
frequency, frequency,
active_profiler: None, active_profiler: None,
} }
} }
} }
impl<'a> Profiler for FlamegraphProfiler<'a> { impl<'a> Profiler for FlamegraphProfiler<'a> {
fn start_profiling(&mut self, _benchmark_id: &str, _benchmark_dir: &Path) { fn start_profiling(&mut self, _benchmark_id: &str, _benchmark_dir: &Path) {
self.active_profiler = Some(ProfilerGuard::new(self.frequency).unwrap()); self.active_profiler = Some(ProfilerGuard::new(self.frequency).unwrap());
} }
fn stop_profiling(&mut self, _benchmark_id: &str, benchmark_dir: &Path) { fn stop_profiling(&mut self, _benchmark_id: &str, benchmark_dir: &Path) {
std::fs::create_dir_all(benchmark_dir).unwrap(); std::fs::create_dir_all(benchmark_dir).unwrap();
let flamegraph_path = benchmark_dir.join("flamegraph.svg"); let flamegraph_path = benchmark_dir.join("flamegraph.svg");
let flamegraph_file = File::create(&flamegraph_path) let flamegraph_file = File::create(&flamegraph_path)
.expect("File system error while creating flamegraph.svg"); .expect("File system error while creating flamegraph.svg");
if let Some(profiler) = self.active_profiler.take() { if let Some(profiler) = self.active_profiler.take() {
profiler profiler
.report() .report()
.build() .build()
.unwrap() .unwrap()
.flamegraph(flamegraph_file) .flamegraph(flamegraph_file)
.expect("Error writing flamegraph"); .expect("Error writing flamegraph");
} }
} }
} }
#[allow(dead_code)] // this infact IS used by benchmarks #[allow(dead_code)] // this infact IS used by benchmarks
fn custom_criterion() -> Criterion { fn custom_criterion() -> Criterion {
Criterion::default() Criterion::default()
.warm_up_time(Duration::from_millis(250)) .warm_up_time(Duration::from_millis(250))
.sample_size(1000) .sample_size(1000)
} }
#[allow(dead_code)] // this infact IS used by benchmarks #[allow(dead_code)] // this infact IS used by benchmarks
fn custom_criterion_flamegraph() -> Criterion { fn custom_criterion_flamegraph() -> Criterion {
custom_criterion().with_profiler(FlamegraphProfiler::new(100)) custom_criterion().with_profiler(FlamegraphProfiler::new(100))
} }
fn mutli_split_function(c: &mut Criterion) { fn mutli_split_function(c: &mut Criterion) {
let data_chars = vec![ let data_chars = vec![
"sin(x)cos(x)", "sin(x)cos(x)",
"x^2", "x^2",
"2x", "2x",
"log10(x)", "log10(x)",
"E^x", "E^x",
"xxxxx", "xxxxx",
"xsin(x)", "xsin(x)",
"(2x+1)(3x+1)", "(2x+1)(3x+1)",
"x**2", "x**2",
"pipipipipipix", "pipipipipipix",
"pi(2x+1)", "pi(2x+1)",
"(2x+1)pi", "(2x+1)pi",
] ]
.iter() .iter()
.map(|a| a.chars().collect::<Vec<char>>()) .map(|a| a.chars().collect::<Vec<char>>())
.collect::<Vec<Vec<char>>>(); .collect::<Vec<Vec<char>>>();
let mut group = c.benchmark_group("split_function"); let mut group = c.benchmark_group("split_function");
for entry in data_chars { for entry in data_chars {
group.bench_function(entry.iter().collect::<String>(), |b| { group.bench_function(entry.iter().collect::<String>(), |b| {
b.iter(|| { b.iter(|| {
split_function_chars(&entry, SplitType::Multiplication); split_function_chars(&entry, SplitType::Multiplication);
}) })
}); });
} }
group.finish(); group.finish();
} }
// Uncomment to enable flamegraph profiling // Uncomment to enable flamegraph profiling

View File

@ -6,8 +6,8 @@ use allsorts::{
tag, tag,
}; };
use epaint::{ use epaint::{
text::{FontData, FontDefinitions, FontTweak},
FontFamily, FontFamily,
text::{FontData, FontDefinitions, FontTweak},
}; };
use std::{ use std::{
collections::BTreeMap, collections::BTreeMap,

View File

@ -138,8 +138,6 @@ impl BackingFunction {
} }
} }
/// Case insensitive checks for if `c` is a character used to represent a variable /// Case insensitive checks for if `c` is a character used to represent a variable
#[inline] #[inline]
pub const fn is_variable(c: &char) -> bool { pub const fn is_variable(c: &char) -> bool {

View File

@ -19,7 +19,13 @@ pub fn widgets_ontop<R>(
/// A toggle button that XORs its state when clicked. /// A toggle button that XORs its state when clicked.
/// Shows different hover text based on current state. /// Shows different hover text based on current state.
pub fn toggle_button(ui: &mut Ui, state: &mut bool, label: &str, enabled_tip: &str, disabled_tip: &str) { pub fn toggle_button(
ui: &mut Ui,
state: &mut bool,
label: &str,
enabled_tip: &str,
disabled_tip: &str,
) {
state.bitxor_assign( state.bitxor_assign(
ui.add(Button::new(label)) ui.add(Button::new(label))
.on_hover_text(if *state { enabled_tip } else { disabled_tip }) .on_hover_text(if *state { enabled_tip } else { disabled_tip })