]> git.lizzy.rs Git - rust.git/blob - src/libcore/bench/mem.rs
Unignore u128 test for stage 0,1
[rust.git] / src / libcore / bench / mem.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 test::Bencher;
12
13 // FIXME #13642 (these benchmarks should be in another place)
14 // Completely miscellaneous language-construct benchmarks.
15 // Static/dynamic method dispatch
16
17 struct Struct {
18     field: isize
19 }
20
21 trait Trait {
22     fn method(&self) -> isize;
23 }
24
25 impl Trait for Struct {
26     fn method(&self) -> isize {
27         self.field
28     }
29 }
30
31 #[bench]
32 fn trait_vtable_method_call(b: &mut Bencher) {
33     let s = Struct { field: 10 };
34     let t = &s as &Trait;
35     b.iter(|| {
36         t.method()
37     });
38 }
39
40 #[bench]
41 fn trait_static_method_call(b: &mut Bencher) {
42     let s = Struct { field: 10 };
43     b.iter(|| {
44         s.method()
45     });
46 }
47
48 // Overhead of various match forms
49
50 #[bench]
51 fn match_option_some(b: &mut Bencher) {
52     let x = Some(10);
53     b.iter(|| {
54         match x {
55             Some(y) => y,
56             None => 11
57         }
58     });
59 }
60
61 #[bench]
62 fn match_vec_pattern(b: &mut Bencher) {
63     let x = [1,2,3,4,5,6];
64     b.iter(|| {
65         match x {
66             [1,2,3,..] => 10,
67             _ => 11,
68         }
69     });
70 }