|
@@ -5,123 +5,203 @@ use std::sync::Arc;
|
|
|
extern crate test;
|
|
|
use test::Bencher;
|
|
|
|
|
|
-#[derive(Clone, Copy)]
|
|
|
-enum MarkDemo {
|
|
|
- Mark0,
|
|
|
- Mark1,
|
|
|
- Mark2,
|
|
|
+fn init_continuous_with_arc<M: Into<XMark>>(
|
|
|
+ xarray: &mut XArray<Arc<i32>, StdMutex, M>,
|
|
|
+ item_num: i32,
|
|
|
+) {
|
|
|
+ for i in 0..item_num {
|
|
|
+ let value = Arc::new(i);
|
|
|
+ xarray.store(i as u64, value);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-impl Into<XMark> for MarkDemo {
|
|
|
- fn into(self) -> XMark {
|
|
|
- match self {
|
|
|
- Self::Mark0 => XMark::Mark0,
|
|
|
- Self::Mark1 => XMark::Mark1,
|
|
|
- Self::Mark2 => XMark::Mark2,
|
|
|
+fn init_sparse_with_arc<M: Into<XMark>>(xarray: &mut XArray<Arc<i32>, StdMutex, M>, item_num: i32) {
|
|
|
+ for i in 0..2 * item_num {
|
|
|
+ if i % 2 == 0 {
|
|
|
+ let value = Arc::new(i);
|
|
|
+ xarray.store(i as u64, value);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#[test]
|
|
|
-fn test_simple_store() {
|
|
|
- let mut xarray_arc: XArray<Arc<i32>, StdMutex> = XArray::new();
|
|
|
+fn test_store_continuous() {
|
|
|
+ let mut xarray_arc: XArray<Arc<i32>> = XArray::new();
|
|
|
+ init_continuous_with_arc(&mut xarray_arc, 10000);
|
|
|
for i in 0..10000 {
|
|
|
- let value = Arc::new(i * 2);
|
|
|
- xarray_arc.store((i * 3) as u64, value);
|
|
|
+ let value = xarray_arc.load(i as u64).unwrap();
|
|
|
+ assert_eq!(*value.as_ref(), i);
|
|
|
}
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn test_store_sparse() {
|
|
|
+ let mut xarray_arc: XArray<Arc<i32>> = XArray::new();
|
|
|
+ init_sparse_with_arc(&mut xarray_arc, 10000);
|
|
|
for i in 0..10000 {
|
|
|
- let value = xarray_arc.load((i * 3) as u64).unwrap();
|
|
|
- assert!(*value.as_ref() == i * 2)
|
|
|
+ if i % 2 == 0 {
|
|
|
+ let value = xarray_arc.load(i as u64).unwrap();
|
|
|
+ assert_eq!(*value.as_ref(), i);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#[test]
|
|
|
-fn test_overwrite_store() {
|
|
|
- let mut xarray_arc: XArray<Arc<i32>, StdMutex> = XArray::new();
|
|
|
-
|
|
|
+fn test_store_overwrite() {
|
|
|
+ let mut xarray_arc: XArray<Arc<i32>> = XArray::new();
|
|
|
+ init_continuous_with_arc(&mut xarray_arc, 10000);
|
|
|
+ // Overwrite 20 at index 10.
|
|
|
let value = Arc::new(20);
|
|
|
xarray_arc.store(10, value);
|
|
|
let v = xarray_arc.load(10).unwrap();
|
|
|
- assert!(*v.as_ref() == 20);
|
|
|
-
|
|
|
+ assert_eq!(*v.as_ref(), 20);
|
|
|
+ // Overwrite 40 at index 10.
|
|
|
let value = Arc::new(40);
|
|
|
xarray_arc.store(10, value);
|
|
|
let v = xarray_arc.load(10).unwrap();
|
|
|
- assert!(*v.as_ref() == 40);
|
|
|
+ assert_eq!(*v.as_ref(), 40);
|
|
|
}
|
|
|
|
|
|
#[test]
|
|
|
fn test_remove() {
|
|
|
- let mut xarray_arc: XArray<Arc<i32>, StdMutex> = XArray::new();
|
|
|
- assert!(xarray_arc.remove(66).is_none());
|
|
|
- for i in 0..10000 {
|
|
|
- let value = Arc::new(i * 2);
|
|
|
- xarray_arc.store(i as u64, value);
|
|
|
- }
|
|
|
+ let mut xarray_arc: XArray<Arc<i32>> = XArray::new();
|
|
|
+ assert!(xarray_arc.remove(100).is_none());
|
|
|
+ init_continuous_with_arc(&mut xarray_arc, 10000);
|
|
|
+
|
|
|
for i in 0..10000 {
|
|
|
- assert!(xarray_arc.remove(i as u64).is_some());
|
|
|
+ assert_eq!(*xarray_arc.remove(i as u64).unwrap().as_ref(), i);
|
|
|
let value = xarray_arc.load(i as u64);
|
|
|
- assert!(value == None);
|
|
|
+ assert_eq!(value, None);
|
|
|
assert!(xarray_arc.remove(i as u64).is_none());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#[test]
|
|
|
-fn test_mark() {
|
|
|
- let mut xarray_arc: XArray<Arc<i32>, StdMutex, MarkDemo> = XArray::new();
|
|
|
- for i in 1..10000 {
|
|
|
- let value = Arc::new(i * 2);
|
|
|
- xarray_arc.store(i as u64, value);
|
|
|
+fn test_cursor_load() {
|
|
|
+ let mut xarray_arc: XArray<Arc<i32>> = XArray::new();
|
|
|
+ init_continuous_with_arc(&mut xarray_arc, 10000);
|
|
|
+
|
|
|
+ let mut cursor = xarray_arc.cursor(0);
|
|
|
+
|
|
|
+ for i in 0..10000 {
|
|
|
+ let value = cursor.load().unwrap();
|
|
|
+ assert_eq!(*value.as_ref(), i);
|
|
|
+ cursor.next();
|
|
|
}
|
|
|
- let mut cursor = xarray_arc.cursor_mut(1000);
|
|
|
- cursor.set_mark(MarkDemo::Mark0).unwrap();
|
|
|
- cursor.set_mark(MarkDemo::Mark1).unwrap();
|
|
|
- cursor.reset_to(2000);
|
|
|
- cursor.set_mark(MarkDemo::Mark1).unwrap();
|
|
|
+
|
|
|
cursor.reset_to(20000);
|
|
|
- assert!(Err(()) == cursor.set_mark(MarkDemo::Mark1));
|
|
|
- assert!(None == cursor.load());
|
|
|
+ assert!(cursor.load().is_none());
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn test_cursor_store_continuous() {
|
|
|
+ let mut xarray_arc: XArray<Arc<i32>> = XArray::new();
|
|
|
+ let mut cursor = xarray_arc.cursor_mut(0);
|
|
|
+
|
|
|
+ for i in 0..10000 {
|
|
|
+ let value = Arc::new(i);
|
|
|
+ cursor.store(value);
|
|
|
+ cursor.next();
|
|
|
+ }
|
|
|
drop(cursor);
|
|
|
|
|
|
- let mut cursor = xarray_arc.cursor(1000);
|
|
|
- let value1 = cursor.load().unwrap();
|
|
|
- let value1_mark0 = cursor.is_marked(MarkDemo::Mark0);
|
|
|
- let value1_mark1 = cursor.is_marked(MarkDemo::Mark1);
|
|
|
+ for i in 0..10000 {
|
|
|
+ let value = xarray_arc.load(i as u64).unwrap();
|
|
|
+ assert_eq!(*value.as_ref(), i);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn test_cursor_store_sparse() {
|
|
|
+ let mut xarray_arc: XArray<Arc<i32>> = XArray::new();
|
|
|
+ let mut cursor = xarray_arc.cursor_mut(0);
|
|
|
+
|
|
|
+ for i in 0..10000 {
|
|
|
+ if i % 2 == 0 {
|
|
|
+ let value = Arc::new(i);
|
|
|
+ cursor.store(value);
|
|
|
+ }
|
|
|
+ cursor.next();
|
|
|
+ }
|
|
|
+ drop(cursor);
|
|
|
+
|
|
|
+ for i in 0..10000 {
|
|
|
+ if i % 2 == 0 {
|
|
|
+ let value = xarray_arc.load(i as u64).unwrap();
|
|
|
+ assert_eq!(*value.as_ref(), i);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn test_set_mark() {
|
|
|
+ let mut xarray_arc: XArray<Arc<i32>, StdMutex, XMark> = XArray::new();
|
|
|
+ init_continuous_with_arc(&mut xarray_arc, 10000);
|
|
|
+
|
|
|
+ let mut cursor = xarray_arc.cursor_mut(1000);
|
|
|
+ cursor.set_mark(XMark::Mark0).unwrap();
|
|
|
+ cursor.set_mark(XMark::Mark1).unwrap();
|
|
|
+ cursor.reset_to(2000);
|
|
|
+ cursor.set_mark(XMark::Mark1).unwrap();
|
|
|
+
|
|
|
+ cursor.reset_to(1000);
|
|
|
+ let value1_mark0 = cursor.is_marked(XMark::Mark0);
|
|
|
+ let value1_mark1 = cursor.is_marked(XMark::Mark1);
|
|
|
|
|
|
cursor.reset_to(2000);
|
|
|
- let value2 = cursor.load().unwrap();
|
|
|
- let value2_mark0 = cursor.is_marked(MarkDemo::Mark0);
|
|
|
- let value2_mark1 = cursor.is_marked(MarkDemo::Mark1);
|
|
|
+ let value2_mark0 = cursor.is_marked(XMark::Mark0);
|
|
|
+ let value2_mark1 = cursor.is_marked(XMark::Mark1);
|
|
|
|
|
|
cursor.reset_to(3000);
|
|
|
- let value3 = cursor.load().unwrap();
|
|
|
- let value3_mark1 = cursor.is_marked(MarkDemo::Mark1);
|
|
|
+ let value3_mark1 = cursor.is_marked(XMark::Mark1);
|
|
|
|
|
|
- assert!(*value1.as_ref() == 2000);
|
|
|
- assert!(*value2.as_ref() == 4000);
|
|
|
- assert!(*value3.as_ref() == 6000);
|
|
|
assert!(value1_mark0 == true);
|
|
|
assert!(value1_mark1 == true);
|
|
|
assert!(value2_mark0 == false);
|
|
|
assert!(value2_mark1 == true);
|
|
|
assert!(value3_mark1 == false);
|
|
|
- drop(cursor);
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn test_unset_mark() {
|
|
|
+ let mut xarray_arc: XArray<Arc<i32>, StdMutex, XMark> = XArray::new();
|
|
|
+ init_continuous_with_arc(&mut xarray_arc, 10000);
|
|
|
|
|
|
let mut cursor = xarray_arc.cursor_mut(1000);
|
|
|
- cursor.unset_mark(MarkDemo::Mark0).unwrap();
|
|
|
- cursor.unset_mark(MarkDemo::Mark2).unwrap();
|
|
|
- drop(cursor);
|
|
|
+ cursor.set_mark(XMark::Mark0).unwrap();
|
|
|
+ cursor.set_mark(XMark::Mark1).unwrap();
|
|
|
|
|
|
- let cursor = xarray_arc.cursor(1000);
|
|
|
- let value1_mark0 = cursor.is_marked(MarkDemo::Mark0);
|
|
|
- let value1_mark2 = cursor.is_marked(MarkDemo::Mark2);
|
|
|
+ cursor.unset_mark(XMark::Mark0).unwrap();
|
|
|
+ cursor.unset_mark(XMark::Mark2).unwrap();
|
|
|
+
|
|
|
+ let value1_mark0 = cursor.is_marked(XMark::Mark0);
|
|
|
+ let value1_mark2 = cursor.is_marked(XMark::Mark2);
|
|
|
assert!(value1_mark0 == false);
|
|
|
assert!(value1_mark2 == false);
|
|
|
- drop(cursor);
|
|
|
+}
|
|
|
|
|
|
- xarray_arc.unset_mark_all(MarkDemo::Mark1);
|
|
|
- let value2_mark1 = xarray_arc.cursor(2000).is_marked(MarkDemo::Mark1);
|
|
|
- assert!(value2_mark1 == false);
|
|
|
+#[test]
|
|
|
+fn test_mark_overflow() {
|
|
|
+ let mut xarray_arc: XArray<Arc<i32>, StdMutex, XMark> = XArray::new();
|
|
|
+ init_continuous_with_arc(&mut xarray_arc, 10000);
|
|
|
+
|
|
|
+ let mut cursor = xarray_arc.cursor_mut(20000);
|
|
|
+ assert!(Err(()) == cursor.set_mark(XMark::Mark1));
|
|
|
+ assert!(false == cursor.is_marked(XMark::Mark1));
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn test_unset_mark_all() {
|
|
|
+ let mut xarray_arc: XArray<Arc<i32>, StdMutex, XMark> = XArray::new();
|
|
|
+ init_continuous_with_arc(&mut xarray_arc, 10000);
|
|
|
+ xarray_arc.cursor_mut(2000).set_mark(XMark::Mark1);
|
|
|
+ xarray_arc.cursor_mut(2000).set_mark(XMark::Mark2);
|
|
|
+ xarray_arc.cursor_mut(200).set_mark(XMark::Mark1);
|
|
|
+ xarray_arc.unset_mark_all(XMark::Mark1);
|
|
|
+
|
|
|
+ assert_eq!(xarray_arc.cursor(2000).is_marked(XMark::Mark1), false);
|
|
|
+ assert_eq!(xarray_arc.cursor(2000).is_marked(XMark::Mark2), true);
|
|
|
+ assert_eq!(xarray_arc.cursor(200).is_marked(XMark::Mark1), false);
|
|
|
}
|
|
|
|
|
|
#[test]
|
|
@@ -147,13 +227,16 @@ fn test_cow() {
|
|
|
Self { raw }
|
|
|
}
|
|
|
}
|
|
|
- let mut xarray_arc: XArray<Arc<Wrapper>, StdMutex> = XArray::new();
|
|
|
+ // Init xarray_arc.
|
|
|
+ let mut xarray_arc: XArray<Arc<Wrapper>> = XArray::new();
|
|
|
for i in 1..10000 {
|
|
|
let value = Arc::new(Wrapper::new(i * 2));
|
|
|
xarray_arc.store(i as u64, value);
|
|
|
}
|
|
|
+ // Clone the xarray_arc.
|
|
|
let mut xarray_clone = xarray_arc.clone();
|
|
|
|
|
|
+ // Store different items in xarray_arc and xarray_clone respectively.
|
|
|
for i in 1..10000 {
|
|
|
if i % 2 == 0 {
|
|
|
let value = Arc::new(Wrapper::new(i * 6));
|
|
@@ -163,7 +246,7 @@ fn test_cow() {
|
|
|
xarray_clone.store(i as u64, value);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ // Determine whether they do not affect each other
|
|
|
for i in 1..10000 {
|
|
|
let value_origin = xarray_arc.load(i).unwrap();
|
|
|
let value_clone = xarray_clone.load(i).unwrap();
|
|
@@ -177,25 +260,26 @@ fn test_cow() {
|
|
|
}
|
|
|
drop(xarray_arc);
|
|
|
drop(xarray_clone);
|
|
|
+ // Check drop times.
|
|
|
assert!(INIT_TIMES.load(Ordering::Relaxed) == DROP_TIMES.load(Ordering::Relaxed));
|
|
|
}
|
|
|
|
|
|
#[test]
|
|
|
fn test_cow_after_cow() {
|
|
|
- let mut xarray_arc: XArray<Arc<u64>, StdMutex> = XArray::new();
|
|
|
+ let mut xarray_arc: XArray<Arc<u64>> = XArray::new();
|
|
|
for i in 1..10000 {
|
|
|
let value = Arc::new(i * 2);
|
|
|
xarray_arc.store(i as u64, value);
|
|
|
}
|
|
|
// First COW.
|
|
|
let mut xarray_cow1 = xarray_arc.clone();
|
|
|
- for i in 5000..6000 {
|
|
|
+ for i in 5000..7000 {
|
|
|
let value = Arc::new(i * 3);
|
|
|
xarray_cow1.store(i as u64, value);
|
|
|
}
|
|
|
// Second COW.
|
|
|
let mut xarray_cow2 = xarray_arc.clone();
|
|
|
- for i in 5500..7000 {
|
|
|
+ for i in 6000..8000 {
|
|
|
let value = Arc::new(i * 4);
|
|
|
xarray_cow2.store(i as u64, value);
|
|
|
}
|
|
@@ -203,20 +287,20 @@ fn test_cow_after_cow() {
|
|
|
let xarray_cow1_cow = xarray_cow1.clone();
|
|
|
let xarray_cow2_cow = xarray_cow2.clone();
|
|
|
|
|
|
- assert!(*xarray_cow1_cow.load(2341).unwrap().as_ref() == 2341 * 2);
|
|
|
+ assert!(*xarray_cow1_cow.load(2000).unwrap().as_ref() == 2000 * 2);
|
|
|
assert!(*xarray_cow1_cow.load(5100).unwrap().as_ref() == 5100 * 3);
|
|
|
- assert!(*xarray_cow1_cow.load(5677).unwrap().as_ref() == 5677 * 3);
|
|
|
- assert!(*xarray_cow1_cow.load(6315).unwrap().as_ref() == 6315 * 2);
|
|
|
+ assert!(*xarray_cow1_cow.load(6100).unwrap().as_ref() == 6100 * 3);
|
|
|
+ assert!(*xarray_cow1_cow.load(7100).unwrap().as_ref() == 7100 * 2);
|
|
|
|
|
|
- assert!(*xarray_cow2_cow.load(2341).unwrap().as_ref() == 2341 * 2);
|
|
|
+ assert!(*xarray_cow2_cow.load(2000).unwrap().as_ref() == 2000 * 2);
|
|
|
assert!(*xarray_cow2_cow.load(5100).unwrap().as_ref() == 5100 * 2);
|
|
|
- assert!(*xarray_cow2_cow.load(5677).unwrap().as_ref() == 5677 * 4);
|
|
|
- assert!(*xarray_cow2_cow.load(6315).unwrap().as_ref() == 6315 * 4);
|
|
|
+ assert!(*xarray_cow2_cow.load(6100).unwrap().as_ref() == 6100 * 4);
|
|
|
+ assert!(*xarray_cow2_cow.load(7100).unwrap().as_ref() == 7100 * 4);
|
|
|
}
|
|
|
|
|
|
#[test]
|
|
|
fn test_cow_mark() {
|
|
|
- let mut xarray_arc: XArray<Arc<i32>, StdMutex, MarkDemo> = XArray::new();
|
|
|
+ let mut xarray_arc: XArray<Arc<i32>, StdMutex, XMark> = XArray::new();
|
|
|
for i in 1..10000 {
|
|
|
let value = Arc::new(i * 2);
|
|
|
xarray_arc.store(i as u64, value);
|
|
@@ -224,25 +308,25 @@ fn test_cow_mark() {
|
|
|
let mut xarray_clone = xarray_arc.clone();
|
|
|
let mut cursor_arc = xarray_arc.cursor_mut(1000);
|
|
|
let mut cursor_clone = xarray_clone.cursor_mut(1000);
|
|
|
- cursor_arc.set_mark(MarkDemo::Mark0).unwrap();
|
|
|
+ cursor_arc.set_mark(XMark::Mark0).unwrap();
|
|
|
cursor_arc.reset_to(2000);
|
|
|
- cursor_arc.set_mark(MarkDemo::Mark0).unwrap();
|
|
|
+ cursor_arc.set_mark(XMark::Mark0).unwrap();
|
|
|
cursor_arc.reset_to(3000);
|
|
|
- cursor_arc.set_mark(MarkDemo::Mark0).unwrap();
|
|
|
+ cursor_arc.set_mark(XMark::Mark0).unwrap();
|
|
|
|
|
|
- cursor_clone.set_mark(MarkDemo::Mark1).unwrap();
|
|
|
+ cursor_clone.set_mark(XMark::Mark1).unwrap();
|
|
|
drop(cursor_arc);
|
|
|
drop(cursor_clone);
|
|
|
|
|
|
- let mark0_1000_arc = xarray_arc.cursor(1000).is_marked(MarkDemo::Mark0);
|
|
|
- let mark0_2000_arc = xarray_arc.cursor(2000).is_marked(MarkDemo::Mark0);
|
|
|
- let mark1_1000_arc = xarray_arc.cursor(1000).is_marked(MarkDemo::Mark1);
|
|
|
- let mark0_3000_arc = xarray_arc.cursor(3000).is_marked(MarkDemo::Mark0);
|
|
|
+ let mark0_1000_arc = xarray_arc.cursor(1000).is_marked(XMark::Mark0);
|
|
|
+ let mark0_2000_arc = xarray_arc.cursor(2000).is_marked(XMark::Mark0);
|
|
|
+ let mark1_1000_arc = xarray_arc.cursor(1000).is_marked(XMark::Mark1);
|
|
|
+ let mark0_3000_arc = xarray_arc.cursor(3000).is_marked(XMark::Mark0);
|
|
|
|
|
|
- let mark0_1000_clone = xarray_clone.cursor(1000).is_marked(MarkDemo::Mark0);
|
|
|
- let mark0_2000_clone = xarray_clone.cursor(2000).is_marked(MarkDemo::Mark0);
|
|
|
- let mark1_1000_clone = xarray_clone.cursor(1000).is_marked(MarkDemo::Mark1);
|
|
|
- let mark0_3000_clone = xarray_clone.cursor(3000).is_marked(MarkDemo::Mark0);
|
|
|
+ let mark0_1000_clone = xarray_clone.cursor(1000).is_marked(XMark::Mark0);
|
|
|
+ let mark0_2000_clone = xarray_clone.cursor(2000).is_marked(XMark::Mark0);
|
|
|
+ let mark1_1000_clone = xarray_clone.cursor(1000).is_marked(XMark::Mark1);
|
|
|
+ let mark0_3000_clone = xarray_clone.cursor(3000).is_marked(XMark::Mark0);
|
|
|
|
|
|
assert!(mark0_1000_arc == true);
|
|
|
assert!(mark0_2000_arc == true);
|
|
@@ -255,33 +339,8 @@ fn test_cow_mark() {
|
|
|
}
|
|
|
|
|
|
#[test]
|
|
|
-fn test_next() {
|
|
|
- let mut xarray_arc: XArray<Arc<i32>, StdMutex> = XArray::new();
|
|
|
- for i in 1..10000 {
|
|
|
- let value = Arc::new(i * 2);
|
|
|
- xarray_arc.store(i as u64, value);
|
|
|
- }
|
|
|
- let mut cursor = xarray_arc.cursor_mut(0);
|
|
|
- for i in 1..10000 {
|
|
|
- cursor.next();
|
|
|
- let value = cursor.load().unwrap();
|
|
|
- assert!(*value.as_ref() == i * 2)
|
|
|
- }
|
|
|
- for i in 0..10000 {
|
|
|
- cursor.next();
|
|
|
- let value = Arc::new((10000 + i) * 2);
|
|
|
- cursor.store(value);
|
|
|
- }
|
|
|
- drop(cursor);
|
|
|
- for i in 10000..20000 {
|
|
|
- let value = xarray_arc.load(i as u64).unwrap();
|
|
|
- assert!(*value.as_ref() == i * 2)
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-#[test]
|
|
|
-fn test_cow_next() {
|
|
|
- let mut xarray_arc: XArray<Arc<u64>, StdMutex> = XArray::new();
|
|
|
+fn test_cow_cursor() {
|
|
|
+ let mut xarray_arc: XArray<Arc<u64>> = XArray::new();
|
|
|
for i in 1..10000 {
|
|
|
let value = Arc::new(i * 2);
|
|
|
xarray_arc.store(i as u64, value);
|
|
@@ -290,14 +349,14 @@ fn test_cow_next() {
|
|
|
|
|
|
let mut cursor_clone = xarray_clone.cursor_mut(1);
|
|
|
let mut cursor_arc = xarray_arc.cursor_mut(1);
|
|
|
- // Use next to read xarray_clone;
|
|
|
+ // Use cursor to read xarray_clone;
|
|
|
while cursor_clone.index() < 10000 {
|
|
|
let item = cursor_clone.load().unwrap();
|
|
|
assert!(*item.as_ref() == cursor_clone.index() * 2);
|
|
|
cursor_clone.next();
|
|
|
}
|
|
|
|
|
|
- // Use next to write xarray_clone;
|
|
|
+ // Use cursor to write xarray_clone;
|
|
|
cursor_clone.reset_to(1);
|
|
|
while cursor_clone.index() < 10000 {
|
|
|
let value = Arc::new(cursor_clone.index());
|
|
@@ -306,14 +365,14 @@ fn test_cow_next() {
|
|
|
cursor_clone.next();
|
|
|
}
|
|
|
|
|
|
- // Use next to read xarray_arc;
|
|
|
+ // Use cursor to read xarray_arc;
|
|
|
while cursor_arc.index() < 10000 {
|
|
|
let item = cursor_arc.load().unwrap();
|
|
|
assert!(*item.as_ref() == cursor_arc.index() * 2);
|
|
|
cursor_arc.next();
|
|
|
}
|
|
|
|
|
|
- // Use next to write xarray_arc;
|
|
|
+ // Use cursor to write xarray_arc;
|
|
|
cursor_arc.reset_to(1);
|
|
|
while cursor_arc.index() < 10000 {
|
|
|
let value = Arc::new(cursor_arc.index() * 3);
|
|
@@ -322,7 +381,7 @@ fn test_cow_next() {
|
|
|
cursor_arc.next();
|
|
|
}
|
|
|
|
|
|
- // Use next to read xarray_arc and xarray_clone;
|
|
|
+ // Use cursor to read xarray_arc and xarray_clone;
|
|
|
cursor_arc.reset_to(1);
|
|
|
cursor_clone.reset_to(1);
|
|
|
while cursor_arc.index() < 10000 {
|
|
@@ -337,7 +396,7 @@ fn test_cow_next() {
|
|
|
|
|
|
#[test]
|
|
|
fn test_range() {
|
|
|
- let mut xarray_arc: XArray<Arc<i32>, StdMutex> = XArray::new();
|
|
|
+ let mut xarray_arc: XArray<Arc<i32>> = XArray::new();
|
|
|
for i in 0..10000 {
|
|
|
let value = Arc::new(i * 2);
|
|
|
xarray_arc.store((i * 2) as u64, value);
|
|
@@ -352,6 +411,16 @@ fn test_range() {
|
|
|
}
|
|
|
|
|
|
#[bench]
|
|
|
-fn benchmark_next(b: &mut Bencher) {
|
|
|
- b.iter(|| test_next());
|
|
|
+fn benchmark_cursor_load(b: &mut Bencher) {
|
|
|
+ b.iter(|| test_cursor_load());
|
|
|
+}
|
|
|
+
|
|
|
+#[bench]
|
|
|
+fn benchmark_cursor_store_continuous(b: &mut Bencher) {
|
|
|
+ b.iter(|| test_cursor_store_continuous());
|
|
|
+}
|
|
|
+
|
|
|
+#[bench]
|
|
|
+fn benchmark_cursor_store_sparse(b: &mut Bencher) {
|
|
|
+ b.iter(|| test_cursor_store_sparse());
|
|
|
}
|