diff options
author | Marge Bot <marge-bot@gnome.org> | 2023-04-25 23:30:10 +0000 |
---|---|---|
committer | Marge Bot <marge-bot@gnome.org> | 2023-04-25 23:30:10 +0000 |
commit | 30567b3eac0148e3e95f5dd011ff76bda5000a99 (patch) | |
tree | 7d5c56dc2b20f91ccc77aee4dad07830e7eb429a /rsvg/benches/path_parser.rs | |
parent | d597831ff93b09cc41ce4768a833bc6407c95184 (diff) | |
parent | 7608c94036d7a44296a7e135f42e84aed20afeb7 (diff) | |
download | librsvg-30567b3eac0148e3e95f5dd011ff76bda5000a99.tar.gz |
Merge branch 'wip/sophie-h/workspace' into 'main'
meta: Move lib and bins into separate crates
Closes #950
See merge request GNOME/librsvg!822
Diffstat (limited to 'rsvg/benches/path_parser.rs')
-rw-r--r-- | rsvg/benches/path_parser.rs | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/rsvg/benches/path_parser.rs b/rsvg/benches/path_parser.rs new file mode 100644 index 00000000..1c0c29ec --- /dev/null +++ b/rsvg/benches/path_parser.rs @@ -0,0 +1,73 @@ +use criterion::{black_box, criterion_group, criterion_main, Criterion}; + +use rsvg::bench_only::Lexer; +use rsvg::bench_only::PathBuilder; + +static INPUT: &'static str = "M10 20 C 30,40 50 60-70,80,90 100,110 120,130,140"; + +static BYTES: &'static [u8; 49] = b"M10 20 C 30,40 50 60-70,80,90 100,110 120,130,140"; + +static SLICE_EDGES: [(usize, usize); 14] = [ + (1, 3), + (4, 6), + (9, 11), + (12, 14), + (15, 17), + (18, 20), + (20, 23), + (24, 26), + (27, 29), + (30, 33), + (34, 37), + (38, 41), + (42, 45), + (46, 49), +]; + +fn lex_path(input: &str) { + let lexer = Lexer::new(black_box(input)); + + for (_pos, _token) in lexer { + // no-op + } +} + +fn path_parser(c: &mut Criterion) { + c.bench_function("parse path into builder", |b| { + let input = black_box(INPUT); + + b.iter(|| { + let mut builder = PathBuilder::default(); + let _ = builder.parse(&input); + }); + }); + + c.bench_function("lex str", |b| { + let input = black_box(INPUT); + + b.iter(|| { + lex_path(input); + }); + }); + + // look at how much time *just* the parse::<i32> part of the lexer should be taking... + c.bench_function("std i32 parse (bytes)", |b| { + let input = black_box(BYTES); + let slice_boundaries = black_box(SLICE_EDGES); + + b.iter(|| { + for (a, b) in slice_boundaries.iter() { + let a: usize = *a; + let b: usize = *b; + unsafe { + let _ = std::str::from_utf8_unchecked(&input[a..b]) + .parse::<i32>() + .unwrap(); + } + } + }); + }); +} + +criterion_group!(benches, path_parser); +criterion_main!(benches); |