summary refs log tree commit diff
path: root/src/libcoretest
diff options
context:
space:
mode:
authorPiotr Czarnecki <pioczarn@gmail.com>2014-08-06 11:20:37 +0100
committerPiotr Czarnecki <pioczarn@gmail.com>2014-08-06 11:20:37 +0100
commita55149b84eba79032567d3d107f73e7a71e358f6 (patch)
treec6c758531f66dc319a8054032c79c52a26f9b08c /src/libcoretest
parent032d5c1dcd95145d58fe3cce63853855578022a7 (diff)
downloadrust-a55149b84eba79032567d3d107f73e7a71e358f6.tar.gz
rust-a55149b84eba79032567d3d107f73e7a71e358f6.zip
core: Refactor iterators
Simplifying the code of methods: nth, fold, rposition
and iterators: Filter, FilterMap, SkipWhile
Adding basic benchmarks
Diffstat (limited to 'src/libcoretest')
-rw-r--r--src/libcoretest/iter.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/libcoretest/iter.rs b/src/libcoretest/iter.rs
index cadbc238e67..d25ffb5b84c 100644
--- a/src/libcoretest/iter.rs
+++ b/src/libcoretest/iter.rs
@@ -14,6 +14,8 @@ use core::uint;
 use core::cmp;
 use core::num;
 
+use test::Bencher;
+
 #[test]
 fn test_lt() {
     let empty: [int, ..0] = [];
@@ -270,6 +272,7 @@ fn test_iterator_nth() {
     for i in range(0u, v.len()) {
         assert_eq!(v.iter().nth(i).unwrap(), &v[i]);
     }
+    assert_eq!(v.iter().nth(v.len()), None);
 }
 
 #[test]
@@ -842,3 +845,31 @@ fn test_iterate() {
     assert_eq!(it.next(), Some(4u));
     assert_eq!(it.next(), Some(8u));
 }
+
+#[bench]
+fn bench_rposition(b: &mut Bencher) {
+    let it: Vec<uint> = range(0u, 300).collect();
+    b.iter(|| {
+        it.iter().rposition(|&x| x <= 150);
+    });
+}
+
+#[bench]
+fn bench_skip_while(b: &mut Bencher) {
+    b.iter(|| {
+        let it = range(0u, 100);
+        let mut sum = 0;
+        it.skip_while(|&x| { sum += x; sum < 4000 }).all(|_| true);
+    });
+}
+
+#[bench]
+fn bench_multiple_take(b: &mut Bencher) {
+    let mut it = range(0u, 42).cycle();
+    b.iter(|| {
+        let n = it.next().unwrap();
+        for m in range(0u, n) {
+            it.take(it.next().unwrap()).all(|_| true);
+        }
+    });
+}