mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Add benchmarks for AtomicRefCell borrows.
This commit is contained in:
parent
987b640c54
commit
79a552ea45
1 changed files with 35 additions and 1 deletions
|
@ -3,6 +3,7 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use style::atomic_refcell::{AtomicRef, AtomicRefCell};
|
use style::atomic_refcell::{AtomicRef, AtomicRefCell};
|
||||||
|
use test::Bencher;
|
||||||
|
|
||||||
struct Foo {
|
struct Foo {
|
||||||
u: u32,
|
u: u32,
|
||||||
|
@ -12,9 +13,15 @@ struct Bar {
|
||||||
f: Foo,
|
f: Foo,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for Bar {
|
||||||
|
fn default() -> Self {
|
||||||
|
Bar { f: Foo { u: 42 } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn map() {
|
fn map() {
|
||||||
let a = AtomicRefCell::new(Bar { f: Foo { u: 42 } });
|
let a = AtomicRefCell::new(Bar::default());
|
||||||
let b = a.borrow();
|
let b = a.borrow();
|
||||||
assert_eq!(b.f.u, 42);
|
assert_eq!(b.f.u, 42);
|
||||||
let c = AtomicRef::map(b, |x| &x.f);
|
let c = AtomicRef::map(b, |x| &x.f);
|
||||||
|
@ -23,6 +30,33 @@ fn map() {
|
||||||
assert_eq!(*d, 42);
|
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
|
/* FIXME(bholley): Enable once we have AtomicRefMut::map(), which is blocked on
|
||||||
* https://github.com/Kimundi/owning-ref-rs/pull/16
|
* https://github.com/Kimundi/owning-ref-rs/pull/16
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue