SHARE
TWEET

Untitled

a guest Jul 17th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #![feature(test)]
  2.  
  3. extern crate test;
  4.  
  5. use test::{black_box, Bencher};
  6. use std::borrow::Cow;
  7.  
  8. const APPEND_LOG: &str = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";
  9.  
  10. #[bench]
  11. fn bench_check_no_alloc(b: &mut Bencher) {
  12.     b.iter(|| {
  13.        no_alloc(black_box(APPEND_LOG))
  14.     })
  15. }
  16.  
  17. #[bench]
  18. fn bench_check(b: &mut Bencher) {
  19.     let v = black_box(APPEND_LOG);
  20.     b.iter(|| {
  21.         v.to_lowercase()
  22.     })
  23. }
  24.  
  25. fn no_alloc(s: &str) -> Cow<str> {
  26.    if s.chars().all(char::is_lowercase) {
  27.        Cow::Borrowed(s)
  28.    } else {
  29.        Cow::Owned(s.to_lowercase())
  30.    }
  31. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top