bench: Fix fallout in benchmarks
diff --git a/src/librustc_back/fs.rs b/src/librustc_back/fs.rs
index 2e4dedd..ea7f244 100644
--- a/src/librustc_back/fs.rs
+++ b/src/librustc_back/fs.rs
@@ -35,7 +35,7 @@
if ret == 0 {
return Err(io::Error::last_os_error())
}
- assert!(ret as usize < v.capacit());
+ assert!(ret as usize < v.capacity());
v.set_len(ret);
}
Ok(PathBuf::from(OsString::from_wide(&v)))
diff --git a/src/test/bench/core-map.rs b/src/test/bench/core-map.rs
index 0cff90d..8f3e939 100644
--- a/src/test/bench/core-map.rs
+++ b/src/test/bench/core-map.rs
@@ -8,11 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-#![feature(unboxed_closures, std_misc, rand)]
+#![feature(std_misc, rand)]
use std::collections::{BTreeMap, HashMap, HashSet};
use std::env;
-use std::rand::{Rng, IsaacRng, SeedableRng};
+use std::__rand::{Rng, thread_rng};
use std::time::Duration;
fn timed<F>(label: &str, f: F) where F: FnMut() {
@@ -114,7 +114,7 @@
{
let seed: &[_] = &[1, 1, 1, 1, 1, 1, 1];
- let mut rng: IsaacRng = SeedableRng::from_seed(seed);
+ let mut rng = thread_rng();
let mut set = HashSet::new();
while set.len() != n_keys {
let next = rng.gen();
diff --git a/src/test/bench/core-std.rs b/src/test/bench/core-std.rs
index 0344d6a..d910367 100644
--- a/src/test/bench/core-std.rs
+++ b/src/test/bench/core-std.rs
@@ -11,18 +11,14 @@
// ignore-lexer-test FIXME #15679
// Microbenchmarks for various functions in std and extra
-#![feature(unboxed_closures, rand, old_io, old_path, std_misc, collections)]
+#![feature(rand, collections, std_misc)]
-use std::old_io::*;
-use std::old_path::{Path, GenericPath};
use std::iter::repeat;
use std::mem::swap;
use std::env;
-use std::rand::Rng;
-use std::rand;
+use std::__rand::{thread_rng, Rng};
use std::str;
use std::time::Duration;
-use std::vec;
fn main() {
let argv: Vec<String> = env::args().collect();
@@ -35,7 +31,6 @@
}
bench!(shift_push);
- bench!(read_line);
bench!(vec_plus);
bench!(vec_append);
bench!(vec_push_all);
@@ -70,21 +65,8 @@
}
}
-fn read_line() {
- use std::old_io::BufferedReader;
-
- let mut path = Path::new(env!("CFG_SRC_DIR"));
- path.push("src/test/bench/shootout-k-nucleotide.data");
-
- for _ in 0..3 {
- let mut reader = BufferedReader::new(File::open(&path).unwrap());
- for _line in reader.lines() {
- }
- }
-}
-
fn vec_plus() {
- let mut r = rand::thread_rng();
+ let mut r = thread_rng();
let mut v = Vec::new();
let mut i = 0;
@@ -102,7 +84,7 @@
}
fn vec_append() {
- let mut r = rand::thread_rng();
+ let mut r = thread_rng();
let mut v = Vec::new();
let mut i = 0;
@@ -123,7 +105,7 @@
}
fn vec_push_all() {
- let mut r = rand::thread_rng();
+ let mut r = thread_rng();
let mut v = Vec::new();
for i in 0..1500 {
diff --git a/src/test/bench/noise.rs b/src/test/bench/noise.rs
index 83c39b3..c21470d 100644
--- a/src/test/bench/noise.rs
+++ b/src/test/bench/noise.rs
@@ -16,7 +16,7 @@
use std::f32::consts::PI;
use std::num::Float;
-use std::rand::{Rng, StdRng};
+use std::__rand::{Rng, thread_rng};
#[derive(Copy, Clone)]
struct Vec2 {
@@ -44,7 +44,7 @@
impl Noise2DContext {
fn new() -> Noise2DContext {
- let mut rng = StdRng::new().unwrap();
+ let mut rng = thread_rng();
let mut rgradients = [Vec2 { x: 0.0, y: 0.0 }; 256];
for x in &mut rgradients[..] {
diff --git a/src/test/bench/shootout-fasta-redux.rs b/src/test/bench/shootout-fasta-redux.rs
index effdd67..145ab71 100644
--- a/src/test/bench/shootout-fasta-redux.rs
+++ b/src/test/bench/shootout-fasta-redux.rs
@@ -38,13 +38,11 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
-#![feature(core, old_io, io, core)]
-
use std::cmp::min;
-use std::old_io::*;
-use std::iter::repeat;
use std::env;
-use std::slice::bytes::copy_memory;
+use std::io;
+use std::io::prelude::*;
+use std::iter::repeat;
const LINE_LEN: usize = 60;
const LOOKUP_SIZE: usize = 4 * 1024;
@@ -116,27 +114,31 @@
out: &'a mut W
}
-impl<'a, W: Writer> RepeatFasta<'a, W> {
+impl<'a, W: Write> RepeatFasta<'a, W> {
fn new(alu: &'static str, w: &'a mut W) -> RepeatFasta<'a, W> {
RepeatFasta { alu: alu, out: w }
}
- fn make(&mut self, n: usize) -> IoResult<()> {
+ fn make(&mut self, n: usize) -> io::Result<()> {
let alu_len = self.alu.len();
let mut buf = repeat(0).take(alu_len + LINE_LEN).collect::<Vec<_>>();
let alu: &[u8] = self.alu.as_bytes();
- copy_memory(alu, &mut buf);
+ for (slot, val) in buf.iter_mut().zip(alu.iter()) {
+ *slot = *val;
+ }
let buf_len = buf.len();
- copy_memory(&alu[..LINE_LEN], &mut buf[alu_len..buf_len]);
+ for (slot, val) in buf[alu_len..buf_len].iter_mut().zip(alu[..LINE_LEN].iter()) {
+ *slot = *val;
+ }
let mut pos = 0;
let mut bytes;
let mut n = n;
while n > 0 {
bytes = min(LINE_LEN, n);
- try!(self.out.write(&buf[pos..pos + bytes]));
- try!(self.out.write_u8('\n' as u8));
+ try!(self.out.write_all(&buf[pos..pos + bytes]));
+ try!(self.out.write_all(&[b'\n']));
pos += bytes;
if pos > alu_len {
pos -= alu_len;
@@ -165,7 +167,7 @@
out: &'a mut W,
}
-impl<'a, W: Writer> RandomFasta<'a, W> {
+impl<'a, W: Write> RandomFasta<'a, W> {
fn new(w: &'a mut W, a: &[AminoAcid]) -> RandomFasta<'a, W> {
RandomFasta {
seed: 42,
@@ -189,7 +191,7 @@
0
}
- fn make(&mut self, n: usize) -> IoResult<()> {
+ fn make(&mut self, n: usize) -> io::Result<()> {
let lines = n / LINE_LEN;
let chars_left = n % LINE_LEN;
let mut buf = [0;LINE_LEN + 1];
@@ -204,7 +206,7 @@
for i in 0..chars_left {
buf[i] = self.nextc();
}
- self.out.write(&buf[..chars_left])
+ self.out.write_all(&buf[..chars_left])
}
}
@@ -216,23 +218,23 @@
5
};
- let mut out = stdout();
+ let mut out = io::stdout();
- out.write_line(">ONE Homo sapiens alu").unwrap();
+ out.write_all(b">ONE Homo sapiens alu\n").unwrap();
{
let mut repeat = RepeatFasta::new(ALU, &mut out);
repeat.make(n * 2).unwrap();
}
- out.write_line(">TWO IUB ambiguity codes").unwrap();
+ out.write_all(b">TWO IUB ambiguity codes\n").unwrap();
let iub = sum_and_scale(&IUB);
let mut random = RandomFasta::new(&mut out, &iub);
random.make(n * 3).unwrap();
- random.out.write_line(">THREE Homo sapiens frequency").unwrap();
+ random.out.write_all(b">THREE Homo sapiens frequency\n").unwrap();
let homo_sapiens = sum_and_scale(&HOMO_SAPIENS);
random.lookup = make_lookup(&homo_sapiens);
random.make(n * 5).unwrap();
- random.out.write_str("\n").unwrap();
+ random.out.write_all(b"\n").unwrap();
}
diff --git a/src/test/bench/shootout-fasta.rs b/src/test/bench/shootout-fasta.rs
index 78d31fa..0474cfb 100644
--- a/src/test/bench/shootout-fasta.rs
+++ b/src/test/bench/shootout-fasta.rs
@@ -38,14 +38,12 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
-#![feature(old_io, old_path, io, core)]
-
use std::cmp::min;
-use std::old_io::*;
-use std::old_io;
-use std::old_path::Path;
-use std::num::Float;
use std::env;
+use std::fs::File;
+use std::io::{self, BufWriter};
+use std::io::prelude::*;
+use std::num::Float;
const LINE_LENGTH: usize = 60;
const IM: u32 = 139968;
@@ -87,9 +85,9 @@
}
}
-fn make_fasta<W: Writer, I: Iterator<Item=u8>>(
+fn make_fasta<W: Write, I: Iterator<Item=u8>>(
wr: &mut W, header: &str, mut it: I, mut n: usize)
- -> std::old_io::IoResult<()>
+ -> io::Result<()>
{
try!(wr.write(header.as_bytes()));
let mut line = [0; LINE_LENGTH + 1];
@@ -105,7 +103,7 @@
Ok(())
}
-fn run<W: Writer>(writer: &mut W) -> std::old_io::IoResult<()> {
+fn run<W: Write>(writer: &mut W) -> io::Result<()> {
let mut args = env::args();
let n = if env::var_os("RUST_BENCH").is_some() {
25000000
@@ -146,10 +144,10 @@
fn main() {
let res = if env::var_os("RUST_BENCH").is_some() {
- let mut file = BufferedWriter::new(File::create(&Path::new("./shootout-fasta.data")));
+ let mut file = BufWriter::new(File::create("./shootout-fasta.data").unwrap());
run(&mut file)
} else {
- run(&mut old_io::stdout())
+ run(&mut io::stdout())
};
res.unwrap()
}
diff --git a/src/test/bench/shootout-k-nucleotide-pipes.rs b/src/test/bench/shootout-k-nucleotide-pipes.rs
index c190641..bcd8fbf 100644
--- a/src/test/bench/shootout-k-nucleotide-pipes.rs
+++ b/src/test/bench/shootout-k-nucleotide-pipes.rs
@@ -13,18 +13,17 @@
// multi tasking k-nucleotide
-#![feature(box_syntax, std_misc, old_io, collections, os)]
+#![allow(bad_style)]
-use std::ascii::{AsciiExt, OwnedAsciiExt};
+use std::ascii::AsciiExt;
use std::cmp::Ordering::{self, Less, Greater, Equal};
use std::collections::HashMap;
use std::mem::replace;
-use std::num::Float;
-use std::option;
-use std::os;
use std::env;
use std::sync::mpsc::{channel, Sender, Receiver};
use std::thread;
+use std::io;
+use std::io::prelude::*;
fn f64_cmp(x: f64, y: f64) -> Ordering {
// arbitrarily decide that NaNs are larger than everything.
@@ -75,10 +74,10 @@
// given a map, search for the frequency of a pattern
fn find(mm: &HashMap<Vec<u8> , usize>, key: String) -> usize {
- let key = key.into_ascii_lowercase();
+ let key = key.to_ascii_lowercase();
match mm.get(key.as_bytes()) {
- option::Option::None => { return 0; }
- option::Option::Some(&num) => { return num; }
+ None => 0,
+ Some(&num) => num,
}
}
@@ -123,7 +122,7 @@
line = from_parent.recv().unwrap();
if line == Vec::new() { break; }
- carry.push_all(&line);
+ carry.extend(line);
carry = windows_with_carry(&carry, sz, |window| {
update_freq(&mut freqs, window);
total += 1;
@@ -147,15 +146,13 @@
// given a FASTA file on stdin, process sequence THREE
fn main() {
- use std::old_io::*;
-
+ let input = io::stdin();
let rdr = if env::var_os("RUST_BENCH").is_some() {
- let foo = include_bytes!("shootout-k-nucleotide.data");
- box MemReader::new(foo.to_vec()) as Box<Reader>
+ let foo: &[u8] = include_bytes!("shootout-k-nucleotide.data");
+ Box::new(foo) as Box<BufRead>
} else {
- box stdio::stdin() as Box<Reader>
+ Box::new(input.lock()) as Box<BufRead>
};
- let mut rdr = BufferedReader::new(rdr);
// initialize each sequence sorter
let sizes: Vec<usize> = vec!(1,2,3,4,6,12,18);
diff --git a/src/test/bench/shootout-mandelbrot.rs b/src/test/bench/shootout-mandelbrot.rs
index d248293..93a0a46 100644
--- a/src/test/bench/shootout-mandelbrot.rs
+++ b/src/test/bench/shootout-mandelbrot.rs
@@ -38,13 +38,13 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
-#![feature(simd, old_io, core, io)]
+#![feature(simd, core)]
// ignore-pretty very bad with line comments
-use std::old_io;
-use std::old_io::*;
use std::env;
+use std::io::prelude::*;
+use std::io;
use std::simd::f64x2;
use std::sync::Arc;
use std::thread;
@@ -53,8 +53,7 @@
const LIMIT: f64 = 2.0;
const WORKERS: usize = 16;
-#[inline(always)]
-fn mandelbrot<W: old_io::Writer>(w: usize, mut out: W) -> old_io::IoResult<()> {
+fn mandelbrot<W: Write>(w: usize, mut out: W) -> io::Result<()> {
assert!(WORKERS % 2 == 0);
// Ensure w and h are multiples of 8.
@@ -142,9 +141,9 @@
})
}).collect::<Vec<_>>();
- try!(writeln!(&mut out as &mut Writer, "P4\n{} {}", w, h));
+ try!(writeln!(&mut out, "P4\n{} {}", w, h));
for res in data {
- try!(out.write(&res.join()));
+ try!(out.write_all(&res.join()));
}
out.flush()
}
@@ -202,9 +201,9 @@
let res = if args.len() < 2 {
println!("Test mode: do not dump the image because it's not utf8, \
which interferes with the test runner.");
- mandelbrot(1000, old_io::util::NullWriter)
+ mandelbrot(1000, io::sink())
} else {
- mandelbrot(args.nth(1).unwrap().parse().unwrap(), old_io::stdout())
+ mandelbrot(args.nth(1).unwrap().parse().unwrap(), io::stdout())
};
res.unwrap();
}
diff --git a/src/test/bench/shootout-reverse-complement.rs b/src/test/bench/shootout-reverse-complement.rs
index cda90c0..96ac1e0 100644
--- a/src/test/bench/shootout-reverse-complement.rs
+++ b/src/test/bench/shootout-reverse-complement.rs
@@ -40,18 +40,18 @@
// ignore-android see #10393 #13206
-#![feature(unboxed_closures, libc, old_io, collections, io, core)]
+#![feature(libc)]
extern crate libc;
-use std::old_io::stdio::{stdin_raw, stdout_raw};
-use std::old_io::*;
-use std::ptr::{copy, Unique};
+use std::io;
+use std::io::prelude::*;
+use std::ptr::copy;
use std::thread;
struct Tables {
- table8: [u8;1 << 8],
- table16: [u16;1 << 16]
+ table8: [u8; 1 << 8],
+ table16: [u16; 1 << 16]
}
impl Tables {
@@ -101,36 +101,6 @@
}
}
-/// Reads all remaining bytes from the stream.
-fn read_to_end<R: Reader>(r: &mut R) -> IoResult<Vec<u8>> {
- // As reading the input stream in memory is a bottleneck, we tune
- // Reader::read_to_end() with a fast growing policy to limit
- // recopies. If MREMAP_RETAIN is implemented in the linux kernel
- // and jemalloc use it, this trick will become useless.
- const CHUNK: usize = 64 * 1024;
-
- let mut vec = Vec::with_capacity(CHUNK);
- loop {
- // workaround: very fast growing
- let len = vec.len();
- if vec.capacity() - len < CHUNK {
- let cap = vec.capacity();
- let mult = if cap < 256 * 1024 * 1024 {
- 16
- } else {
- 2
- };
- vec.reserve_exact(mult * cap - len);
- }
- match r.push_at_least(1, CHUNK, &mut vec) {
- Ok(_) => {}
- Err(ref e) if e.kind == EndOfFile => break,
- Err(e) => return Err(e)
- }
- }
- Ok(vec)
-}
-
/// Finds the first position at which `b` occurs in `s`.
fn memchr(h: &[u8], n: u8) -> Option<usize> {
use libc::{c_void, c_int, size_t};
@@ -175,7 +145,8 @@
/// Compute the reverse complement.
fn reverse_complement(seq: &mut [u8], tables: &Tables) {
- let seq = seq.init_mut();// Drop the last newline
+ let len = seq.len();
+ let seq = &mut seq[..len - 1]; // Drop the last newline
let len = seq.len();
let off = LINE_LEN - len % (LINE_LEN + 1);
let mut i = LINE_LEN;
@@ -222,26 +193,20 @@
}
}
-
-struct Racy<T>(T);
-
-unsafe impl<T: 'static> Send for Racy<T> {}
-
/// Executes a closure in parallel over the given iterator over mutable slice.
/// The closure `f` is run in parallel with an element of `iter`.
-fn parallel<'a, I: Iterator, F>(iter: I, ref f: F)
- where I::Item: Send + 'a,
- F: Fn(I::Item) + Sync + 'a {
+fn parallel<I: Iterator, F>(iter: I, ref f: F)
+ where I::Item: Send,
+ F: Fn(I::Item) + Sync, {
iter.map(|x| {
- thread::scoped(move|| {
- f(x)
- })
+ thread::scoped(move || f(x))
}).collect::<Vec<_>>();
}
fn main() {
- let mut data = read_to_end(&mut stdin_raw()).unwrap();
+ let mut data = Vec::with_capacity(1024 * 1024);
+ io::stdin().read_to_end(&mut data);
let tables = &Tables::new();
parallel(mut_dna_seqs(&mut data), |seq| reverse_complement(seq, tables));
- stdout_raw().write(&data).unwrap();
+ io::stdout().write_all(&data).unwrap();
}
diff --git a/src/test/debuginfo/function-arg-initialization.rs b/src/test/debuginfo/function-arg-initialization.rs
index d611e4a..a1ca59c 100644
--- a/src/test/debuginfo/function-arg-initialization.rs
+++ b/src/test/debuginfo/function-arg-initialization.rs
@@ -10,15 +10,15 @@
// min-lldb-version: 310
-// This test case checks if function arguments already have the correct value when breaking at the
-// first line of the function, that is if the function prologue has already been executed at the
-// first line. Note that because of the __morestack part of the prologue GDB incorrectly breaks at
-// before the arguments have been properly loaded when setting the breakpoint via the function name.
+// This test case checks if function arguments already have the correct value
+// when breaking at the first line of the function, that is if the function
+// prologue has already been executed at the first line. Note that because of
+// the __morestack part of the prologue GDB incorrectly breaks at before the
+// arguments have been properly loaded when setting the breakpoint via the
+// function name.
// compile-flags:-g
-#![feature(old_io)]
-
// === GDB TESTS ===================================================================================
// gdb-command:run
@@ -227,7 +227,7 @@
#![omit_gdb_pretty_printer_section]
fn immediate_args(a: isize, b: bool, c: f64) {
- ::std::old_io::print("") // #break
+ println!("") // #break
}
struct BigStruct {
@@ -242,21 +242,21 @@
}
fn non_immediate_args(a: BigStruct, b: BigStruct) {
- ::std::old_io::print("") // #break
+ println!("") // #break
}
fn binding(a: i64, b: u64, c: f64) {
let x = 0; // #break
- ::std::old_io::print("")
+ println!("")
}
fn assignment(mut a: u64, b: u64, c: f64) {
a = b; // #break
- ::std::old_io::print("")
+ println!("")
}
fn function_call(x: u64, y: u64, z: f64) {
- std::old_io::stdio::print("Hi!") // #break
+ println!("Hi!") // #break
}
fn identifier(x: u64, y: u64, z: f64) -> u64 {
diff --git a/src/test/debuginfo/function-prologue-stepping-no-stack-check.rs b/src/test/debuginfo/function-prologue-stepping-no-stack-check.rs
index 0608e49..7e959a1 100644
--- a/src/test/debuginfo/function-prologue-stepping-no-stack-check.rs
+++ b/src/test/debuginfo/function-prologue-stepping-no-stack-check.rs
@@ -11,17 +11,17 @@
// ignore-android: FIXME(#10381)
// min-lldb-version: 310
-// This test case checks if function arguments already have the correct value when breaking at the
-// beginning of a function. Functions with the #[no_stack_check] attribute have the same prologue as
-// regular C functions compiled with GCC or Clang and therefore are better handled by GDB. As a
-// consequence, and as opposed to regular Rust functions, we can set the breakpoints via the
-// function name (and don't have to fall back on using line numbers). For LLDB this shouldn't make
-// a difference because it can handle both cases.
+// This test case checks if function arguments already have the correct value
+// when breaking at the beginning of a function. Functions with the
+// #[no_stack_check] attribute have the same prologue as regular C functions
+// compiled with GCC or Clang and therefore are better handled by GDB. As a
+// consequence, and as opposed to regular Rust functions, we can set the
+// breakpoints via the function name (and don't have to fall back on using line
+// numbers). For LLDB this shouldn't make a difference because it can handle
+// both cases.
// compile-flags:-g
-#![feature(old_io)]
-
// === GDB TESTS ===================================================================================
// gdb-command:rbreak immediate_args
@@ -251,7 +251,7 @@
#[no_stack_check]
fn immediate_args(a: isize, b: bool, c: f64) {
- ::std::old_io::print("");
+ println!("");
}
struct BigStruct {
@@ -267,24 +267,24 @@
#[no_stack_check]
fn non_immediate_args(a: BigStruct, b: BigStruct) {
- ::std::old_io::print("");
+ println!("");
}
#[no_stack_check]
fn binding(a: i64, b: u64, c: f64) {
let x = 0;
- ::std::old_io::print("");
+ println!("");
}
#[no_stack_check]
fn assignment(mut a: u64, b: u64, c: f64) {
a = b;
- ::std::old_io::print("");
+ println!("");
}
#[no_stack_check]
fn function_call(x: u64, y: u64, z: f64) {
- std::old_io::stdio::print("Hi!")
+ println!("Hi!")
}
#[no_stack_check]
diff --git a/src/test/debuginfo/issue13213.rs b/src/test/debuginfo/issue13213.rs
index 38b149e..13dc0c6 100644
--- a/src/test/debuginfo/issue13213.rs
+++ b/src/test/debuginfo/issue13213.rs
@@ -23,5 +23,5 @@
// be available because they have been optimized out from the exporting crate.
fn main() {
let b: issue13213aux::S = issue13213aux::A;
- ::std::old_io::println("Nothing to do here...");
+ println!("Nothing to do here...");
}