diff --git a/tests/unit/style/atomic_refcell.rs b/tests/unit/style/atomic_refcell.rs index 4aba6bf6c00..4e6e36d0f8f 100644 --- a/tests/unit/style/atomic_refcell.rs +++ b/tests/unit/style/atomic_refcell.rs @@ -3,6 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use style::atomic_refcell::{AtomicRef, AtomicRefCell}; +use test::Bencher; struct Foo { u: u32, @@ -12,9 +13,15 @@ struct Bar { f: Foo, } +impl Default for Bar { + fn default() -> Self { + Bar { f: Foo { u: 42 } } + } +} + #[test] fn map() { - let a = AtomicRefCell::new(Bar { f: Foo { u: 42 } }); + let a = AtomicRefCell::new(Bar::default()); let b = a.borrow(); assert_eq!(b.f.u, 42); let c = AtomicRef::map(b, |x| &x.f); @@ -23,6 +30,33 @@ fn map() { assert_eq!(*d, 42); } +#[bench] +fn immutable_borrow(b: &mut Bencher) { + let a = AtomicRefCell::new(Bar::default()); + b.iter(|| a.borrow()); +} + +#[bench] +fn immutable_second_borrow(b: &mut Bencher) { + let a = AtomicRefCell::new(Bar::default()); + let _first = a.borrow(); + b.iter(|| a.borrow()); +} + +#[bench] +fn immutable_third_borrow(b: &mut Bencher) { + let a = AtomicRefCell::new(Bar::default()); + let _first = a.borrow(); + let _second = a.borrow(); + b.iter(|| a.borrow()); +} + +#[bench] +fn mutable_borrow(b: &mut Bencher) { + let a = AtomicRefCell::new(Bar::default()); + b.iter(|| a.borrow_mut()); +} + /* FIXME(bholley): Enable once we have AtomicRefMut::map(), which is blocked on * https://github.com/Kimundi/owning-ref-rs/pull/16 #[test]