]> git.lizzy.rs Git - rust.git/blob - src/libcollections/benches/vec_deque.rs
Rollup merge of #39604 - est31:i128_tests, r=alexcrichton
[rust.git] / src / libcollections / benches / vec_deque.rs
1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 use std::collections::VecDeque;
12 use test::{Bencher, black_box};
13
14 #[bench]
15 fn bench_new(b: &mut Bencher) {
16     b.iter(|| {
17         let ring: VecDeque<i32> = VecDeque::new();
18         black_box(ring);
19     })
20 }
21
22 #[bench]
23 fn bench_grow_1025(b: &mut Bencher) {
24     b.iter(|| {
25         let mut deq = VecDeque::new();
26         for i in 0..1025 {
27             deq.push_front(i);
28         }
29         black_box(deq);
30     })
31 }
32
33 #[bench]
34 fn bench_iter_1000(b: &mut Bencher) {
35     let ring: VecDeque<_> = (0..1000).collect();
36
37     b.iter(|| {
38         let mut sum = 0;
39         for &i in &ring {
40             sum += i;
41         }
42         black_box(sum);
43     })
44 }
45
46 #[bench]
47 fn bench_mut_iter_1000(b: &mut Bencher) {
48     let mut ring: VecDeque<_> = (0..1000).collect();
49
50     b.iter(|| {
51         let mut sum = 0;
52         for i in &mut ring {
53             sum += *i;
54         }
55         black_box(sum);
56     })
57 }