make ./x.py bench again

This commit is contained in:
Mazdak Farrokhzad 2019-11-23 07:06:27 +01:00
parent a449535bbc
commit 59257e6e88
5 changed files with 63 additions and 65 deletions

View file

@ -35,7 +35,7 @@ macro_rules! from_str_bench {
.iter()
.cycle()
.take(5_000)
.filter_map(|s| <($t)>::from_str(s).ok())
.filter_map(|s| <$t>::from_str(s).ok())
.max()
})
}
@ -51,7 +51,7 @@ macro_rules! from_str_radix_bench {
.iter()
.cycle()
.take(5_000)
.filter_map(|s| <($t)>::from_str_radix(s, $radix).ok())
.filter_map(|s| <$t>::from_str_radix(s, $radix).ok())
.max()
})
}

View file

@ -1,34 +0,0 @@
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 &Trait;
b.iter(|| {
t.method()
});
}
#[bench]
fn trait_static_method_call(b: &mut Bencher) {
let s = Struct { field: 10 };
b.iter(|| {
s.method()
});
}

View file

@ -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,
}
});
}

View file

@ -1,25 +0,0 @@
use test::Bencher;
// 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,
}
});
}

View file

@ -52,7 +52,7 @@ fn test_minimize2() {
fn test_rpath_relative() {
if cfg!(target_os = "macos") {
let config = &mut RPathConfig {
used_crates: Vec::new(),
used_crates: &[],
has_rpath: true,
is_like_osx: true,
linker_is_gnu: false,
@ -64,7 +64,7 @@ fn test_rpath_relative() {
assert_eq!(res, "@loader_path/../lib");
} else {
let config = &mut RPathConfig {
used_crates: Vec::new(),
used_crates: &[],
out_filename: PathBuf::from("bin/rustc"),
get_install_prefix_lib_path: &mut || panic!(),
has_rpath: true,