performance improvements

This commit is contained in:
Simon Gardling
2022-05-04 11:11:38 -04:00
parent d57609217a
commit 05614782d1
3 changed files with 19 additions and 13 deletions

View File

@@ -55,6 +55,7 @@ fn custom_criterion() -> Criterion {
Criterion::default() Criterion::default()
// .with_profiler(FlamegraphProfiler::new(100)) // .with_profiler(FlamegraphProfiler::new(100))
.warm_up_time(Duration::from_millis(250)) .warm_up_time(Duration::from_millis(250))
.sample_size(1000)
} }
#[criterion(custom_criterion())] #[criterion(custom_criterion())]
@@ -79,15 +80,11 @@ fn split_function_bench(c: &mut Criterion) {
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_with_input( group.bench_function(entry.iter().collect::<String>(), |b| {
BenchmarkId::new("split_function", entry.iter().collect::<String>()),
&entry,
|b, i| {
b.iter(|| { b.iter(|| {
split_function_chars(i); split_function_chars(&entry);
}) })
}, });
);
} }
group.finish(); group.finish();
} }

View File

@@ -1,4 +1,5 @@
#![feature(const_trait_impl)] #![feature(const_trait_impl)]
#![feature(core_intrinsics)]
pub mod parsing; pub mod parsing;
pub mod suggestions; pub mod suggestions;

View File

@@ -1,3 +1,5 @@
use std::intrinsics::assume;
use crate::parsing::is_variable; use crate::parsing::is_variable;
pub const HINT_EMPTY: Hint = Hint::Single("x^2"); pub const HINT_EMPTY: Hint = Hint::Single("x^2");
@@ -35,7 +37,7 @@ pub fn split_function_chars(chars: &[char]) -> Vec<String> {
} }
// Resulting split-up data // Resulting split-up data
let mut data: Vec<String> = Vec::with_capacity(chars.len()); let mut data: Vec<Vec<&char>> = Vec::with_capacity(chars.len());
// Buffer used to store data ready to be appended // Buffer used to store data ready to be appended
let mut buffer: Vec<&char> = Vec::with_capacity(chars.len()); let mut buffer: Vec<&char> = Vec::with_capacity(chars.len());
@@ -156,7 +158,7 @@ pub fn split_function_chars(chars: &[char]) -> Vec<String> {
// Append split // Append split
if do_split { if do_split {
data.push(buffer.iter().cloned().collect::<String>()); data.push(buffer.clone());
buffer.clear(); buffer.clear();
} }
@@ -169,10 +171,16 @@ pub fn split_function_chars(chars: &[char]) -> Vec<String> {
// If there is still data in the buffer, append it // If there is still data in the buffer, append it
if !buffer.is_empty() { if !buffer.is_empty() {
data.push(buffer.iter().cloned().collect::<String>()); data.push(buffer);
} }
data unsafe {
assume(!data.is_empty());
}
data.iter()
.map(|e| e.iter().cloned().collect::<String>())
.collect()
} }
/// Generate a hint based on the input `input`, returns an `Option<String>` /// Generate a hint based on the input `input`, returns an `Option<String>`