-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
63 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,63 @@ | ||
#![feature(slice_patterns)] | ||
#![feature(test)] | ||
|
||
extern crate test; | ||
|
||
mod dispatch; | ||
mod pattern; | ||
use test::Bencher; | ||
|
||
// Static/dynamic method dispatch | ||
|
||
struct Struct { | ||
field: isize | ||
} | ||
|
||
trait Trait { | ||
fn method(&self) -> isize; | ||
} | ||
|
||
impl Trait for Struct { | ||
fn method(&self) -> isize { | ||
self.field | ||
} | ||
} | ||
|
||
#[bench] | ||
fn trait_vtable_method_call(b: &mut Bencher) { | ||
let s = Struct { field: 10 }; | ||
let t = &s as &dyn Trait; | ||
b.iter(|| { | ||
t.method() | ||
}); | ||
} | ||
|
||
#[bench] | ||
fn trait_static_method_call(b: &mut Bencher) { | ||
let s = Struct { field: 10 }; | ||
b.iter(|| { | ||
s.method() | ||
}); | ||
} | ||
|
||
// Overhead of various match forms | ||
|
||
#[bench] | ||
fn option_some(b: &mut Bencher) { | ||
let x = Some(10); | ||
b.iter(|| { | ||
match x { | ||
Some(y) => y, | ||
None => 11 | ||
} | ||
}); | ||
} | ||
|
||
#[bench] | ||
fn vec_pattern(b: &mut Bencher) { | ||
let x = [1,2,3,4,5,6]; | ||
b.iter(|| { | ||
match x { | ||
[1,2,3,..] => 10, | ||
_ => 11, | ||
} | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters