statement.rs 832 B

123456789101112131415161718192021222324252627282930
  1. use criterion::*;
  2. use ion_shell::parser::{StatementSplitter, Terminator};
  3. use itertools::Itertools;
  4. const TEXT: &[u8] = include_bytes!("test.ion");
  5. fn criterion_benchmark(c: &mut Criterion) {
  6. let stmts = TEXT
  7. .iter()
  8. .copied()
  9. .batching(|lines| Terminator::new(lines).terminate())
  10. .collect::<Vec<_>>();
  11. c.bench(
  12. "statement-splitter-throughput",
  13. ParameterizedBenchmark::new(
  14. "statement",
  15. |b, script| {
  16. b.iter(|| {
  17. script.iter().flat_map(|cmd| StatementSplitter::new(cmd)).collect::<Vec<_>>()
  18. })
  19. },
  20. vec![stmts],
  21. )
  22. .throughput(|script| Throughput::Bytes(script.len() as u64)),
  23. );
  24. }
  25. criterion_group!(benches, criterion_benchmark);
  26. criterion_main!(benches);