Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 12 pull requests #39567

Merged
merged 32 commits into from
Feb 5, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3ccb87a
liballoc_jemalloc: fix linking with system library
ishitatsuyuki Feb 3, 2017
458167e
Add `aarch64-unknown-freebsd` to the supported targets
dumbbell Jan 25, 2017
f6c6b31
`aarch64` CPU type is called `arm64` on FreeBSD
dumbbell Feb 3, 2017
5e41ec2
rename other than copy/remove
king6cong Feb 1, 2017
7de99cd
Merge remote tracking branch 'upstream/master'
ishitatsuyuki Feb 3, 2017
768f6a9
add and use rename_or_copy_remove fn that fallback to copy & remove
king6cong Feb 3, 2017
d14b268
libbacktrace: Fix uninitialized variable
petrochenkov Feb 3, 2017
34f444d
Extract libcore benchmarks to a separate folder
phungleson Feb 3, 2017
efeb42b
Use less syscalls in `FileDesc::set_{nonblocking,cloexec}`
tbu- Feb 4, 2017
3c16139
Don't use "unadjusted" ABI on non windows platforms
est31 Feb 2, 2017
5a21f42
run rustfmt for librustc/util/fs.rs
king6cong Feb 4, 2017
87ace0d
More snap cleanup
nagisa Feb 4, 2017
206ee20
Unignore stage0/1 i128 tests as well
nagisa Feb 4, 2017
a1f42cd
Uninhabited while-let pattern fix
canndrew Feb 4, 2017
768c6c0
Support a debug info API change for LLVM 4.0
Feb 4, 2017
112a5a0
ignore more gdb versions with buggy rust support
TimNN Feb 4, 2017
a884a6c
Slightly optimize slice::sort
Feb 4, 2017
fa457bf
Minor fix in the *_expensive benchmark
Feb 4, 2017
0dbb1e4
Remove use of ptr::eq
canndrew Feb 5, 2017
7135d0a
Fix make tidy
canndrew Feb 5, 2017
388db66
Rollup merge of #39439 - king6cong:move, r=alexcrichton
frewsxcv Feb 5, 2017
ddd01e0
Rollup merge of #39472 - est31:unadjusted_only_for_win, r=nagisa
frewsxcv Feb 5, 2017
d021a3f
Rollup merge of #39481 - ishitatsuyuki:master, r=alexcrichton
frewsxcv Feb 5, 2017
b3518af
Rollup merge of #39491 - dumbbell:support-aarch64-unknown-freebsd, r=…
frewsxcv Feb 5, 2017
ac329cd
Rollup merge of #39501 - phungleson:libcorebench, r=alexcrichton
frewsxcv Feb 5, 2017
ae3aafa
Rollup merge of #39509 - petrochenkov:rb2, r=alexcrichton
frewsxcv Feb 5, 2017
d194688
Rollup merge of #39514 - tbu-:pr_less_syscalls_fd, r=alexcrichton
frewsxcv Feb 5, 2017
13b8e4b
Rollup merge of #39519 - nagisa:more-snap, r=alexcrichton
frewsxcv Feb 5, 2017
4e67bf9
Rollup merge of #39526 - canndrew:uninhabited-while-let-fix, r=arielb1
frewsxcv Feb 5, 2017
3e7ee35
Rollup merge of #39528 - dylanmckay:llvm-4.0-diglobalvar, r=alexcrichton
frewsxcv Feb 5, 2017
70cc1d3
Rollup merge of #39530 - TimNN:more-gdb, r=alexcrichton
frewsxcv Feb 5, 2017
a419dd1
Rollup merge of #39538 - stjepang:slightly-optimize-sort, r=alexcrichton
frewsxcv Feb 5, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/libcore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ bench = false
name = "coretest"
path = "../libcoretest/lib.rs"

# FIXME: need to extract benchmarks to a separate crate
#[[bench]]
#name = "coretest"
#path = "../libcoretest/lib.rs"
[[bench]]
name = "corebench"
path = "../libcore/bench/lib.rs"
22 changes: 22 additions & 0 deletions src/libcore/bench/any.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use core::any::*;
use test::{Bencher, black_box};

#[bench]
fn bench_downcast_ref(b: &mut Bencher) {
b.iter(|| {
let mut x = 0;
let mut y = &mut x as &mut Any;
black_box(&mut y);
black_box(y.downcast_ref::<isize>() == Some(&0));
});
}
11 changes: 11 additions & 0 deletions src/libcore/bench/hash/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

mod sip;
151 changes: 151 additions & 0 deletions src/libcore/bench/hash/sip.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![allow(deprecated)]

use core::hash::*;
use test::{Bencher, black_box};

fn hash_bytes<H: Hasher>(mut s: H, x: &[u8]) -> u64 {
Hasher::write(&mut s, x);
s.finish()
}

fn hash_with<H: Hasher, T: Hash>(mut st: H, x: &T) -> u64 {
x.hash(&mut st);
st.finish()
}

fn hash<T: Hash>(x: &T) -> u64 {
hash_with(SipHasher::new(), x)
}

#[bench]
fn bench_str_under_8_bytes(b: &mut Bencher) {
let s = "foo";
b.iter(|| {
assert_eq!(hash(&s), 16262950014981195938);
})
}

#[bench]
fn bench_str_of_8_bytes(b: &mut Bencher) {
let s = "foobar78";
b.iter(|| {
assert_eq!(hash(&s), 4898293253460910787);
})
}

#[bench]
fn bench_str_over_8_bytes(b: &mut Bencher) {
let s = "foobarbaz0";
b.iter(|| {
assert_eq!(hash(&s), 10581415515220175264);
})
}

#[bench]
fn bench_long_str(b: &mut Bencher) {
let s = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor \
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud \
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute \
irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla \
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui \
officia deserunt mollit anim id est laborum.";
b.iter(|| {
assert_eq!(hash(&s), 17717065544121360093);
})
}

#[bench]
fn bench_u32(b: &mut Bencher) {
let u = 162629500u32;
let u = black_box(u);
b.iter(|| {
hash(&u)
});
b.bytes = 8;
}

#[bench]
fn bench_u32_keyed(b: &mut Bencher) {
let u = 162629500u32;
let u = black_box(u);
let k1 = black_box(0x1);
let k2 = black_box(0x2);
b.iter(|| {
hash_with(SipHasher::new_with_keys(k1, k2), &u)
});
b.bytes = 8;
}

#[bench]
fn bench_u64(b: &mut Bencher) {
let u = 16262950014981195938u64;
let u = black_box(u);
b.iter(|| {
hash(&u)
});
b.bytes = 8;
}

#[bench]
fn bench_bytes_4(b: &mut Bencher) {
let data = black_box([b' '; 4]);
b.iter(|| {
hash_bytes(SipHasher::default(), &data)
});
b.bytes = 4;
}

#[bench]
fn bench_bytes_7(b: &mut Bencher) {
let data = black_box([b' '; 7]);
b.iter(|| {
hash_bytes(SipHasher::default(), &data)
});
b.bytes = 7;
}

#[bench]
fn bench_bytes_8(b: &mut Bencher) {
let data = black_box([b' '; 8]);
b.iter(|| {
hash_bytes(SipHasher::default(), &data)
});
b.bytes = 8;
}

#[bench]
fn bench_bytes_a_16(b: &mut Bencher) {
let data = black_box([b' '; 16]);
b.iter(|| {
hash_bytes(SipHasher::default(), &data)
});
b.bytes = 16;
}

#[bench]
fn bench_bytes_b_32(b: &mut Bencher) {
let data = black_box([b' '; 32]);
b.iter(|| {
hash_bytes(SipHasher::default(), &data)
});
b.bytes = 32;
}

#[bench]
fn bench_bytes_c_128(b: &mut Bencher) {
let data = black_box([b' '; 128]);
b.iter(|| {
hash_bytes(SipHasher::default(), &data)
});
b.bytes = 128;
}
101 changes: 101 additions & 0 deletions src/libcore/bench/iter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use core::iter::*;
use test::{Bencher, black_box};

#[bench]
fn bench_rposition(b: &mut Bencher) {
let it: Vec<usize> = (0..300).collect();
b.iter(|| {
it.iter().rposition(|&x| x <= 150);
});
}

#[bench]
fn bench_skip_while(b: &mut Bencher) {
b.iter(|| {
let it = 0..100;
let mut sum = 0;
it.skip_while(|&x| { sum += x; sum < 4000 }).all(|_| true);
});
}

#[bench]
fn bench_multiple_take(b: &mut Bencher) {
let mut it = (0..42).cycle();
b.iter(|| {
let n = it.next().unwrap();
for _ in 0..n {
it.clone().take(it.next().unwrap()).all(|_| true);
}
});
}

fn scatter(x: i32) -> i32 { (x * 31) % 127 }

#[bench]
fn bench_max_by_key(b: &mut Bencher) {
b.iter(|| {
let it = 0..100;
it.max_by_key(|&x| scatter(x))
})
}

// http://www.reddit.com/r/rust/comments/31syce/using_iterators_to_find_the_index_of_the_min_or/
#[bench]
fn bench_max_by_key2(b: &mut Bencher) {
fn max_index_iter(array: &[i32]) -> usize {
array.iter().enumerate().max_by_key(|&(_, item)| item).unwrap().0
}

let mut data = vec![0; 1638];
data[514] = 9999;

b.iter(|| max_index_iter(&data));
}

#[bench]
fn bench_max(b: &mut Bencher) {
b.iter(|| {
let it = 0..100;
it.map(scatter).max()
})
}

pub fn copy_zip(xs: &[u8], ys: &mut [u8]) {
for (a, b) in ys.iter_mut().zip(xs) {
*a = *b;
}
}

pub fn add_zip(xs: &[f32], ys: &mut [f32]) {
for (a, b) in ys.iter_mut().zip(xs) {
*a += *b;
}
}

#[bench]
fn bench_zip_copy(b: &mut Bencher) {
let source = vec![0u8; 16 * 1024];
let mut dst = black_box(vec![0u8; 16 * 1024]);
b.iter(|| {
copy_zip(&source, &mut dst)
})
}

#[bench]
fn bench_zip_add(b: &mut Bencher) {
let source = vec![1.; 16 * 1024];
let mut dst = vec![0.; 16 * 1024];
b.iter(|| {
add_zip(&source, &mut dst)
});
}
25 changes: 25 additions & 0 deletions src/libcore/bench/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![deny(warnings)]

#![feature(flt2dec)]
#![feature(slice_patterns)]
#![feature(test)]

extern crate core;
extern crate test;

mod any;
mod hash;
mod iter;
mod mem;
mod num;
mod ops;
70 changes: 70 additions & 0 deletions src/libcore/bench/mem.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use test::Bencher;

// FIXME #13642 (these benchmarks should be in another place)
// Completely miscellaneous language-construct benchmarks.
// 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()
});
}

// Overhead of various match forms

#[bench]
fn match_option_some(b: &mut Bencher) {
let x = Some(10);
b.iter(|| {
match x {
Some(y) => y,
None => 11
}
});
}

#[bench]
fn match_vec_pattern(b: &mut Bencher) {
let x = [1,2,3,4,5,6];
b.iter(|| {
match x {
[1,2,3,..] => 10,
_ => 11,
}
});
}
Loading