pub struct BatchParser { /* private fields */ }Expand description
Efficient batch parser with an internal token cache and optional volatility classifier.
The cache is keyed by the original formula string; repeated formulas across a batch (very common in spreadsheets) will avoid re-tokenization and whitespace filtering.
Implementations§
Source§impl BatchParser
impl BatchParser
Sourcepub fn builder() -> BatchParserBuilder
pub fn builder() -> BatchParserBuilder
Examples found in repository?
examples/parser_guard_bench.rs (line 157)
153fn main() {
154 println!("workload,iterations,sources,elapsed_ns,ns_per_parse,digest");
155 for c in corpus() {
156 let digest = semantic_digest(&c.formulas);
157 let builder = BatchParser::builder();
158 let builder = if let Ok(entries) = std::env::var("BENCH_CACHE_ENTRIES") {
159 builder.cache_capacity(entries.parse().unwrap(), usize::MAX)
160 } else {
161 builder
162 };
163 let mut batch = builder.build();
164 // Warm allocator, code and the full working set. Pre-existing token
165 // cache warmup is retained intentionally to reveal eviction thrashing.
166 let unique = c.name == "batch_unique_stream";
167 let warm_count = if unique {
168 4096
169 } else {
170 c.formulas.len().max(4096)
171 };
172 for i in 0..warm_count {
173 let other = unique.then(|| format!("=X{i}+Y{i}*$C$1"));
174 let f = other
175 .as_deref()
176 .unwrap_or(&c.formulas[i % c.formulas.len()]);
177 consume(if c.batch {
178 batch.parse(f).unwrap()
179 } else {
180 parse(f).unwrap()
181 });
182 }
183 let start = Instant::now();
184 for i in 0..c.iterations {
185 let f = black_box(&c.formulas[i % c.formulas.len()]);
186 consume(if c.batch {
187 batch.parse(f).unwrap()
188 } else {
189 parse(f).unwrap()
190 });
191 }
192 let elapsed = start.elapsed().as_nanos();
193 println!(
194 "{},{},{},{},{:.3},{:016x}",
195 c.name,
196 c.iterations,
197 c.formulas.len(),
198 elapsed,
199 elapsed as f64 / c.iterations as f64,
200 digest
201 );
202 }
203}Sourcepub fn parse(&mut self, formula: &str) -> Result<ASTNode, ParserError>
pub fn parse(&mut self, formula: &str) -> Result<ASTNode, ParserError>
Parse a formula using the internal cache and configured classifier.
Examples found in repository?
examples/parser_guard_bench.rs (line 178)
153fn main() {
154 println!("workload,iterations,sources,elapsed_ns,ns_per_parse,digest");
155 for c in corpus() {
156 let digest = semantic_digest(&c.formulas);
157 let builder = BatchParser::builder();
158 let builder = if let Ok(entries) = std::env::var("BENCH_CACHE_ENTRIES") {
159 builder.cache_capacity(entries.parse().unwrap(), usize::MAX)
160 } else {
161 builder
162 };
163 let mut batch = builder.build();
164 // Warm allocator, code and the full working set. Pre-existing token
165 // cache warmup is retained intentionally to reveal eviction thrashing.
166 let unique = c.name == "batch_unique_stream";
167 let warm_count = if unique {
168 4096
169 } else {
170 c.formulas.len().max(4096)
171 };
172 for i in 0..warm_count {
173 let other = unique.then(|| format!("=X{i}+Y{i}*$C$1"));
174 let f = other
175 .as_deref()
176 .unwrap_or(&c.formulas[i % c.formulas.len()]);
177 consume(if c.batch {
178 batch.parse(f).unwrap()
179 } else {
180 parse(f).unwrap()
181 });
182 }
183 let start = Instant::now();
184 for i in 0..c.iterations {
185 let f = black_box(&c.formulas[i % c.formulas.len()]);
186 consume(if c.batch {
187 batch.parse(f).unwrap()
188 } else {
189 parse(f).unwrap()
190 });
191 }
192 let elapsed = start.elapsed().as_nanos();
193 println!(
194 "{},{},{},{},{:.3},{:016x}",
195 c.name,
196 c.iterations,
197 c.formulas.len(),
198 elapsed,
199 elapsed as f64 / c.iterations as f64,
200 digest
201 );
202 }
203}Auto Trait Implementations§
impl !RefUnwindSafe for BatchParser
impl !UnwindSafe for BatchParser
impl Freeze for BatchParser
impl Send for BatchParser
impl Sync for BatchParser
impl Unpin for BatchParser
impl UnsafeUnpin for BatchParser
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more