Skip to content

Commit 941d92c

Browse files
committed
Benchmark for impl FromIterator for Result.
(This is an attempt to ensure we do not regress performance here, since the performance of this operation varied pretty wildly of the course of rust-lang#11084.)
1 parent 0ba7d41 commit 941d92c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/libcore/benches/iter.rs

+12
Original file line numberDiff line numberDiff line change
@@ -344,3 +344,15 @@ fn bench_partial_cmp(b: &mut Bencher) {
344344
fn bench_lt(b: &mut Bencher) {
345345
b.iter(|| (0..100000).map(black_box).lt((0..100000).map(black_box)))
346346
}
347+
348+
// rust-lang/rust#11084: benchmark how built-in `FromIterator` for
349+
// `Result` performs, to avoid unknowingly regressing its performance.
350+
#[bench]
351+
fn bench_result_from_iter_into_vec(b: &mut Bencher) {
352+
let expected = vec![1; 1000];
353+
let v: Vec<Result<isize, String>> = vec![Ok(1); 1000];
354+
b.iter(|| {
355+
let result: Result<Vec<isize>, String> = FromIterator::from_iter(v.iter().cloned());
356+
assert_eq!(result.unwrap(), expected);
357+
});
358+
}

0 commit comments

Comments
 (0)