diff --git a/tamer/benches/sym.rs b/tamer/benches/sym.rs index 786f97a4..1bab589d 100644 --- a/tamer/benches/sym.rs +++ b/tamer/benches/sym.rs @@ -164,6 +164,34 @@ mod interner { }); } + // Unlike the above, which already has a UTF-8 string, this actually + // performs a conversion and check from `&[u8]`. + #[bench] + fn with_all_new_1000_utf8_checked(bench: &mut Bencher) { + let strs = gen_strs(1000); + let bs: Vec<&[u8]> = strs.iter().map(|s| s.as_bytes()).collect(); + + bench.iter(|| { + let sut = ArenaInterner::::new(); + bs.iter() + .map(|b| sut.intern(std::str::from_utf8(&b).unwrap())) + .for_each(drop); + }); + } + + #[bench] + fn with_all_new_1000_utf8_unchecked(bench: &mut Bencher) { + let strs = gen_strs(1000); + let bs: Vec<&[u8]> = strs.iter().map(|s| s.as_bytes()).collect(); + + bench.iter(|| { + let sut = ArenaInterner::::new(); + bs.iter() + .map(|b| unsafe { sut.intern_utf8_unchecked(&b) }) + .for_each(drop); + }); + } + #[bench] fn with_all_new_uninterned_1000(bench: &mut Bencher) { let strs = gen_strs(1000); @@ -193,6 +221,18 @@ mod interner { }); } + // Unlike the above, which already has a UTF-8 string, this actually + // performs a conversion and check from `&[u8]`. + #[bench] + fn with_one_new_1000_utf8_checked(bench: &mut Bencher) { + bench.iter(|| { + let sut = ArenaInterner::::new(); + (0..1000) + .map(|_| sut.intern(std::str::from_utf8(b"first").unwrap())) + .for_each(drop); + }); + } + #[bench] fn with_one_new_1000_utf8_unchecked(bench: &mut Bencher) { bench.iter(|| {