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 168)
164fn main() {
165 println!("workload,iterations,sources,elapsed_ns,ns_per_parse,digest");
166 for c in corpus() {
167 let digest = semantic_digest(&c.formulas);
168 let builder = BatchParser::builder();
169 let builder = if let Ok(entries) = std::env::var("BENCH_CACHE_ENTRIES") {
170 builder.cache_capacity(entries.parse().unwrap(), usize::MAX)
171 } else {
172 builder
173 };
174 let mut batch = builder.build();
175 // Warm allocator, code and the full working set. Pre-existing token
176 // cache warmup is retained intentionally to reveal eviction thrashing.
177 let unique = c.name == "batch_unique_stream";
178 let warm_count = if unique {
179 4096
180 } else {
181 c.formulas.len().max(4096)
182 };
183 for i in 0..warm_count {
184 let other = unique.then(|| format!("=X{i}+Y{i}*$C$1"));
185 let f = other
186 .as_deref()
187 .unwrap_or(&c.formulas[i % c.formulas.len()]);
188 consume(if c.batch {
189 batch.parse(f).unwrap()
190 } else {
191 parse(f).unwrap()
192 });
193 }
194 let start = Instant::now();
195 for i in 0..c.iterations {
196 let f = black_box(&c.formulas[i % c.formulas.len()]);
197 consume(if c.batch {
198 batch.parse(f).unwrap()
199 } else {
200 parse(f).unwrap()
201 });
202 }
203 let elapsed = start.elapsed().as_nanos();
204 println!(
205 "{},{},{},{},{:.3},{:016x}",
206 c.name,
207 c.iterations,
208 c.formulas.len(),
209 elapsed,
210 elapsed as f64 / c.iterations as f64,
211 digest
212 );
213 }
214}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 189)
164fn main() {
165 println!("workload,iterations,sources,elapsed_ns,ns_per_parse,digest");
166 for c in corpus() {
167 let digest = semantic_digest(&c.formulas);
168 let builder = BatchParser::builder();
169 let builder = if let Ok(entries) = std::env::var("BENCH_CACHE_ENTRIES") {
170 builder.cache_capacity(entries.parse().unwrap(), usize::MAX)
171 } else {
172 builder
173 };
174 let mut batch = builder.build();
175 // Warm allocator, code and the full working set. Pre-existing token
176 // cache warmup is retained intentionally to reveal eviction thrashing.
177 let unique = c.name == "batch_unique_stream";
178 let warm_count = if unique {
179 4096
180 } else {
181 c.formulas.len().max(4096)
182 };
183 for i in 0..warm_count {
184 let other = unique.then(|| format!("=X{i}+Y{i}*$C$1"));
185 let f = other
186 .as_deref()
187 .unwrap_or(&c.formulas[i % c.formulas.len()]);
188 consume(if c.batch {
189 batch.parse(f).unwrap()
190 } else {
191 parse(f).unwrap()
192 });
193 }
194 let start = Instant::now();
195 for i in 0..c.iterations {
196 let f = black_box(&c.formulas[i % c.formulas.len()]);
197 consume(if c.batch {
198 batch.parse(f).unwrap()
199 } else {
200 parse(f).unwrap()
201 });
202 }
203 let elapsed = start.elapsed().as_nanos();
204 println!(
205 "{},{},{},{},{:.3},{:016x}",
206 c.name,
207 c.iterations,
208 c.formulas.len(),
209 elapsed,
210 elapsed as f64 / c.iterations as f64,
211 digest
212 );
213 }
214}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