File tree Expand file tree Collapse file tree 1 file changed +29
-6
lines changed
src/librustc_data_structures/tiny_list Expand file tree Collapse file tree 1 file changed +29
-6
lines changed Original file line number Diff line number Diff line change 11use super :: * ;
22
33extern crate test;
4- use test:: Bencher ;
4+ use test:: { Bencher , black_box } ;
55
66#[ test]
77fn test_contains_and_insert ( ) {
@@ -98,36 +98,59 @@ fn test_remove_single() {
9898#[ bench]
9999fn bench_insert_empty ( b : & mut Bencher ) {
100100 b. iter ( || {
101- let mut list = TinyList :: new ( ) ;
101+ let mut list = black_box ( TinyList :: new ( ) ) ;
102102 list. insert ( 1 ) ;
103+ list
103104 } )
104105}
105106
106107#[ bench]
107108fn bench_insert_one ( b : & mut Bencher ) {
108109 b. iter ( || {
109- let mut list = TinyList :: new_single ( 0 ) ;
110+ let mut list = black_box ( TinyList :: new_single ( 0 ) ) ;
110111 list. insert ( 1 ) ;
112+ list
111113 } )
112114}
113115
116+ #[ bench]
117+ fn bench_contains_empty ( b : & mut Bencher ) {
118+ b. iter ( || {
119+ black_box ( TinyList :: new ( ) ) . contains ( & 1 )
120+ } ) ;
121+ }
122+
123+ #[ bench]
124+ fn bench_contains_unknown ( b : & mut Bencher ) {
125+ b. iter ( || {
126+ black_box ( TinyList :: new_single ( 0 ) ) . contains ( & 1 )
127+ } ) ;
128+ }
129+
130+ #[ bench]
131+ fn bench_contains_one ( b : & mut Bencher ) {
132+ b. iter ( || {
133+ black_box ( TinyList :: new_single ( 1 ) ) . contains ( & 1 )
134+ } ) ;
135+ }
136+
114137#[ bench]
115138fn bench_remove_empty ( b : & mut Bencher ) {
116139 b. iter ( || {
117- TinyList :: new ( ) . remove ( & 1 )
140+ black_box ( TinyList :: new ( ) ) . remove ( & 1 )
118141 } ) ;
119142}
120143
121144#[ bench]
122145fn bench_remove_unknown ( b : & mut Bencher ) {
123146 b. iter ( || {
124- TinyList :: new_single ( 0 ) . remove ( & 1 )
147+ black_box ( TinyList :: new_single ( 0 ) ) . remove ( & 1 )
125148 } ) ;
126149}
127150
128151#[ bench]
129152fn bench_remove_one ( b : & mut Bencher ) {
130153 b. iter ( || {
131- TinyList :: new_single ( 1 ) . remove ( & 1 )
154+ black_box ( TinyList :: new_single ( 1 ) ) . remove ( & 1 )
132155 } ) ;
133156}
You can’t perform that action at this time.
0 commit comments