Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![feature(test)]
- extern crate test;
- use test::{black_box, Bencher};
- use std::borrow::Cow;
- const APPEND_LOG: &str = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";
- #[bench]
- fn bench_check_no_alloc(b: &mut Bencher) {
- b.iter(|| {
- no_alloc(black_box(APPEND_LOG))
- })
- }
- #[bench]
- fn bench_check(b: &mut Bencher) {
- let v = black_box(APPEND_LOG);
- b.iter(|| {
- v.to_lowercase()
- })
- }
- fn no_alloc(s: &str) -> Cow<str> {
- if s.chars().all(char::is_lowercase) {
- Cow::Borrowed(s)
- } else {
- Cow::Owned(s.to_lowercase())
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement