time: Deprecate the library in the distribution
This commit deprecates the entire libtime library in favor of the externally-provided libtime in the rust-lang organization. Users of the `libtime` crate as-is today should add this to their Cargo manifests: [dependencies.time] git = "https://github.com/rust-lang/time" To implement this transition, a new function `Duration::span` was added to the `std::time::Duration` time. This function takes a closure and then returns the duration of time it took that closure to execute. This interface will likely improve with `FnOnce` unboxed closures as moving in and out will be a little easier. Due to the deprecation of the in-tree crate, this is a: [breaking-change] cc #18855, some of the conversions in the `src/test/bench` area may have been a little nicer with that implemented
This commit is contained in:
parent
e4ead7b034
commit
fcd05ed99f
22 changed files with 329 additions and 266 deletions
|
@ -41,7 +41,6 @@ extern crate rustc_llvm;
|
||||||
extern crate rustc_back;
|
extern crate rustc_back;
|
||||||
extern crate serialize;
|
extern crate serialize;
|
||||||
extern crate rbml;
|
extern crate rbml;
|
||||||
extern crate time;
|
|
||||||
#[phase(plugin, link)] extern crate log;
|
#[phase(plugin, link)] extern crate log;
|
||||||
#[phase(plugin, link)] extern crate syntax;
|
#[phase(plugin, link)] extern crate syntax;
|
||||||
|
|
||||||
|
|
|
@ -228,16 +228,16 @@ use util::fs;
|
||||||
|
|
||||||
use std::c_str::ToCStr;
|
use std::c_str::ToCStr;
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
|
use std::collections::hash_map::{Occupied, Vacant};
|
||||||
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::io::fs::PathExtensions;
|
use std::io::fs::PathExtensions;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::slice;
|
use std::slice;
|
||||||
use std::string;
|
use std::string;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use std::collections::{HashMap, HashSet};
|
|
||||||
use std::collections::hash_map::{Occupied, Vacant};
|
|
||||||
use flate;
|
use flate;
|
||||||
use time;
|
|
||||||
|
|
||||||
pub struct CrateMismatch {
|
pub struct CrateMismatch {
|
||||||
path: Path,
|
path: Path,
|
||||||
|
@ -691,11 +691,13 @@ impl ArchiveMetadata {
|
||||||
|
|
||||||
// Just a small wrapper to time how long reading metadata takes.
|
// Just a small wrapper to time how long reading metadata takes.
|
||||||
fn get_metadata_section(is_osx: bool, filename: &Path) -> Result<MetadataBlob, String> {
|
fn get_metadata_section(is_osx: bool, filename: &Path) -> Result<MetadataBlob, String> {
|
||||||
let start = time::precise_time_ns();
|
let mut ret = None;
|
||||||
let ret = get_metadata_section_imp(is_osx, filename);
|
let dur = Duration::span(|| {
|
||||||
|
ret = Some(get_metadata_section_imp(is_osx, filename));
|
||||||
|
});
|
||||||
info!("reading {} => {}ms", filename.filename_display(),
|
info!("reading {} => {}ms", filename.filename_display(),
|
||||||
(time::precise_time_ns() - start) / 1000000);
|
dur.num_milliseconds());
|
||||||
return ret;
|
return ret.unwrap();;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_metadata_section_imp(is_osx: bool, filename: &Path) -> Result<MetadataBlob, String> {
|
fn get_metadata_section_imp(is_osx: bool, filename: &Path) -> Result<MetadataBlob, String> {
|
||||||
|
|
|
@ -97,8 +97,6 @@ use syntax::visit::Visitor;
|
||||||
use syntax::visit;
|
use syntax::visit;
|
||||||
use syntax::{ast, ast_util, ast_map};
|
use syntax::{ast, ast_util, ast_map};
|
||||||
|
|
||||||
use time;
|
|
||||||
|
|
||||||
local_data_key!(task_local_insn_key: RefCell<Vec<&'static str>>)
|
local_data_key!(task_local_insn_key: RefCell<Vec<&'static str>>)
|
||||||
|
|
||||||
pub fn with_insn_ctxt(blk: |&[&'static str]|) {
|
pub fn with_insn_ctxt(blk: |&[&'static str]|) {
|
||||||
|
@ -138,23 +136,16 @@ pub fn push_ctxt(s: &'static str) -> _InsnCtxt {
|
||||||
pub struct StatRecorder<'a, 'tcx: 'a> {
|
pub struct StatRecorder<'a, 'tcx: 'a> {
|
||||||
ccx: &'a CrateContext<'a, 'tcx>,
|
ccx: &'a CrateContext<'a, 'tcx>,
|
||||||
name: Option<String>,
|
name: Option<String>,
|
||||||
start: u64,
|
|
||||||
istart: uint,
|
istart: uint,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> StatRecorder<'a, 'tcx> {
|
impl<'a, 'tcx> StatRecorder<'a, 'tcx> {
|
||||||
pub fn new(ccx: &'a CrateContext<'a, 'tcx>, name: String)
|
pub fn new(ccx: &'a CrateContext<'a, 'tcx>, name: String)
|
||||||
-> StatRecorder<'a, 'tcx> {
|
-> StatRecorder<'a, 'tcx> {
|
||||||
let start = if ccx.sess().trans_stats() {
|
|
||||||
time::precise_time_ns()
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
};
|
|
||||||
let istart = ccx.stats().n_llvm_insns.get();
|
let istart = ccx.stats().n_llvm_insns.get();
|
||||||
StatRecorder {
|
StatRecorder {
|
||||||
ccx: ccx,
|
ccx: ccx,
|
||||||
name: Some(name),
|
name: Some(name),
|
||||||
start: start,
|
|
||||||
istart: istart,
|
istart: istart,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -164,11 +155,8 @@ impl<'a, 'tcx> StatRecorder<'a, 'tcx> {
|
||||||
impl<'a, 'tcx> Drop for StatRecorder<'a, 'tcx> {
|
impl<'a, 'tcx> Drop for StatRecorder<'a, 'tcx> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
if self.ccx.sess().trans_stats() {
|
if self.ccx.sess().trans_stats() {
|
||||||
let end = time::precise_time_ns();
|
|
||||||
let elapsed = ((end - self.start) / 1_000_000) as uint;
|
|
||||||
let iend = self.ccx.stats().n_llvm_insns.get();
|
let iend = self.ccx.stats().n_llvm_insns.get();
|
||||||
self.ccx.stats().fn_stats.borrow_mut().push((self.name.take().unwrap(),
|
self.ccx.stats().fn_stats.borrow_mut().push((self.name.take().unwrap(),
|
||||||
elapsed,
|
|
||||||
iend - self.istart));
|
iend - self.istart));
|
||||||
self.ccx.stats().n_fns.set(self.ccx.stats().n_fns.get() + 1);
|
self.ccx.stats().n_fns.set(self.ccx.stats().n_fns.get() + 1);
|
||||||
// Reset LLVM insn count to avoid compound costs.
|
// Reset LLVM insn count to avoid compound costs.
|
||||||
|
@ -3097,13 +3085,13 @@ pub fn trans_crate<'tcx>(analysis: CrateAnalysis<'tcx>)
|
||||||
println!("n_inlines: {}", stats.n_inlines.get());
|
println!("n_inlines: {}", stats.n_inlines.get());
|
||||||
println!("n_closures: {}", stats.n_closures.get());
|
println!("n_closures: {}", stats.n_closures.get());
|
||||||
println!("fn stats:");
|
println!("fn stats:");
|
||||||
stats.fn_stats.borrow_mut().sort_by(|&(_, _, insns_a), &(_, _, insns_b)| {
|
stats.fn_stats.borrow_mut().sort_by(|&(_, insns_a), &(_, insns_b)| {
|
||||||
insns_b.cmp(&insns_a)
|
insns_b.cmp(&insns_a)
|
||||||
});
|
});
|
||||||
for tuple in stats.fn_stats.borrow().iter() {
|
for tuple in stats.fn_stats.borrow().iter() {
|
||||||
match *tuple {
|
match *tuple {
|
||||||
(ref name, ms, insns) => {
|
(ref name, insns) => {
|
||||||
println!("{} insns, {} ms, {}", insns, ms, *name);
|
println!("{} insns, {}", insns, *name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,8 +47,8 @@ pub struct Stats {
|
||||||
pub n_closures: Cell<uint>,
|
pub n_closures: Cell<uint>,
|
||||||
pub n_llvm_insns: Cell<uint>,
|
pub n_llvm_insns: Cell<uint>,
|
||||||
pub llvm_insns: RefCell<FnvHashMap<String, uint>>,
|
pub llvm_insns: RefCell<FnvHashMap<String, uint>>,
|
||||||
// (ident, time-in-ms, llvm-instructions)
|
// (ident, llvm-instructions)
|
||||||
pub fn_stats: RefCell<Vec<(String, uint, uint)> >,
|
pub fn_stats: RefCell<Vec<(String, uint)> >,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The shared portion of a `CrateContext`. There is one `SharedCrateContext`
|
/// The shared portion of a `CrateContext`. There is one `SharedCrateContext`
|
||||||
|
|
|
@ -12,14 +12,14 @@
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::hash::{Hash, Hasher};
|
|
||||||
use std::fmt::Show;
|
use std::fmt::Show;
|
||||||
|
use std::hash::{Hash, Hasher};
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::visit;
|
use syntax::visit;
|
||||||
use syntax::visit::Visitor;
|
use syntax::visit::Visitor;
|
||||||
|
|
||||||
use time;
|
|
||||||
|
|
||||||
pub fn time<T, U>(do_it: bool, what: &str, u: U, f: |U| -> T) -> T {
|
pub fn time<T, U>(do_it: bool, what: &str, u: U, f: |U| -> T) -> T {
|
||||||
local_data_key!(depth: uint);
|
local_data_key!(depth: uint);
|
||||||
if !do_it { return f(u); }
|
if !do_it { return f(u); }
|
||||||
|
@ -27,11 +27,15 @@ pub fn time<T, U>(do_it: bool, what: &str, u: U, f: |U| -> T) -> T {
|
||||||
let old = depth.get().map(|d| *d).unwrap_or(0);
|
let old = depth.get().map(|d| *d).unwrap_or(0);
|
||||||
depth.replace(Some(old + 1));
|
depth.replace(Some(old + 1));
|
||||||
|
|
||||||
let start = time::precise_time_s();
|
let mut u = Some(u);
|
||||||
let rv = f(u);
|
let mut rv = None;
|
||||||
let end = time::precise_time_s();
|
let dur = Duration::span(|| {
|
||||||
|
rv = Some(f(u.take().unwrap()))
|
||||||
|
});
|
||||||
|
let rv = rv.unwrap();
|
||||||
|
|
||||||
println!("{}time: {:3.3f} s\t{}", " ".repeat(old), end - start, what);
|
println!("{}time: {}.{:03} \t{}", " ".repeat(old),
|
||||||
|
dur.num_seconds(), dur.num_milliseconds(), what);
|
||||||
depth.replace(Some(old));
|
depth.replace(Some(old));
|
||||||
|
|
||||||
rv
|
rv
|
||||||
|
|
|
@ -25,7 +25,6 @@ extern crate rustc;
|
||||||
extern crate serialize;
|
extern crate serialize;
|
||||||
extern crate syntax;
|
extern crate syntax;
|
||||||
extern crate "test" as testing;
|
extern crate "test" as testing;
|
||||||
extern crate time;
|
|
||||||
#[phase(plugin, link)] extern crate log;
|
#[phase(plugin, link)] extern crate log;
|
||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
|
@ -238,7 +237,6 @@ pub fn main_args(args: &[String]) -> int {
|
||||||
};
|
};
|
||||||
|
|
||||||
info!("going to format");
|
info!("going to format");
|
||||||
let started = time::precise_time_ns();
|
|
||||||
match matches.opt_str("w").as_ref().map(|s| s.as_slice()) {
|
match matches.opt_str("w").as_ref().map(|s| s.as_slice()) {
|
||||||
Some("html") | None => {
|
Some("html") | None => {
|
||||||
match html::render::run(krate, &external_html, output.unwrap_or(Path::new("doc"))) {
|
match html::render::run(krate, &external_html, output.unwrap_or(Path::new("doc"))) {
|
||||||
|
@ -257,8 +255,6 @@ pub fn main_args(args: &[String]) -> int {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let ended = time::precise_time_ns();
|
|
||||||
info!("Took {:.03f}s", (ended as f64 - started as f64) / 1e9f64);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,6 +135,14 @@ impl Duration {
|
||||||
Duration { secs: secs, nanos: nanos as i32 }
|
Duration { secs: secs, nanos: nanos as i32 }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Runs a closure, returning the duration of time it took to run the
|
||||||
|
/// closure.
|
||||||
|
pub fn span(f: ||) -> Duration {
|
||||||
|
let before = super::precise_time_ns();
|
||||||
|
f();
|
||||||
|
Duration::nanoseconds((before - super::precise_time_ns()) as i64)
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the total number of whole weeks in the duration.
|
/// Returns the total number of whole weeks in the duration.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn num_weeks(&self) -> i64 {
|
pub fn num_weeks(&self) -> i64 {
|
||||||
|
|
|
@ -10,6 +10,79 @@
|
||||||
|
|
||||||
//! Temporal quantification.
|
//! Temporal quantification.
|
||||||
|
|
||||||
|
use libc;
|
||||||
|
|
||||||
pub use self::duration::Duration;
|
pub use self::duration::Duration;
|
||||||
|
|
||||||
pub mod duration;
|
pub mod duration;
|
||||||
|
|
||||||
|
/// Returns the current value of a high-resolution performance counter
|
||||||
|
/// in nanoseconds since an unspecified epoch.
|
||||||
|
// NB: this is intentionally not public, this is not ready to stabilize its api.
|
||||||
|
fn precise_time_ns() -> u64 {
|
||||||
|
return os_precise_time_ns();
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
fn os_precise_time_ns() -> u64 {
|
||||||
|
let mut ticks_per_s = 0;
|
||||||
|
assert_eq!(unsafe {
|
||||||
|
libc::QueryPerformanceFrequency(&mut ticks_per_s)
|
||||||
|
}, 1);
|
||||||
|
let ticks_per_s = if ticks_per_s == 0 {1} else {ticks_per_s};
|
||||||
|
let mut ticks = 0;
|
||||||
|
assert_eq!(unsafe {
|
||||||
|
libc::QueryPerformanceCounter(&mut ticks)
|
||||||
|
}, 1);
|
||||||
|
|
||||||
|
return (ticks as u64 * 1000000000) / (ticks_per_s as u64);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
||||||
|
fn os_precise_time_ns() -> u64 {
|
||||||
|
use sync;
|
||||||
|
|
||||||
|
static mut TIMEBASE: libc::mach_timebase_info = libc::mach_timebase_info { numer: 0,
|
||||||
|
denom: 0 };
|
||||||
|
static ONCE: sync::Once = sync::ONCE_INIT;
|
||||||
|
unsafe {
|
||||||
|
ONCE.doit(|| {
|
||||||
|
imp::mach_timebase_info(&mut TIMEBASE);
|
||||||
|
});
|
||||||
|
let time = imp::mach_absolute_time();
|
||||||
|
time * TIMEBASE.numer as u64 / TIMEBASE.denom as u64
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(any(windows, target_os = "macos", target_os = "ios")))]
|
||||||
|
fn os_precise_time_ns() -> u64 {
|
||||||
|
let mut ts = libc::timespec { tv_sec: 0, tv_nsec: 0 };
|
||||||
|
unsafe {
|
||||||
|
imp::clock_gettime(libc::CLOCK_MONOTONIC, &mut ts);
|
||||||
|
}
|
||||||
|
return (ts.tv_sec as u64) * 1000000000 + (ts.tv_nsec as u64)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(all(unix, not(target_os = "macos"), not(target_os = "ios")))]
|
||||||
|
mod imp {
|
||||||
|
use libc::{c_int, timespec};
|
||||||
|
|
||||||
|
// Apparently android provides this in some other library?
|
||||||
|
#[cfg(not(target_os = "android"))]
|
||||||
|
#[link(name = "rt")]
|
||||||
|
extern {}
|
||||||
|
|
||||||
|
extern {
|
||||||
|
pub fn clock_gettime(clk_id: c_int, tp: *mut timespec) -> c_int;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
||||||
|
mod imp {
|
||||||
|
use libc::{c_int, mach_timebase_info};
|
||||||
|
|
||||||
|
extern {
|
||||||
|
pub fn mach_absolute_time() -> u64;
|
||||||
|
pub fn mach_timebase_info(info: *mut mach_timebase_info) -> c_int;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -39,11 +39,9 @@ extern crate getopts;
|
||||||
extern crate regex;
|
extern crate regex;
|
||||||
extern crate serialize;
|
extern crate serialize;
|
||||||
extern crate term;
|
extern crate term;
|
||||||
extern crate time;
|
|
||||||
|
|
||||||
use std::collections::TreeMap;
|
use std::collections::TreeMap;
|
||||||
use stats::Stats;
|
use stats::Stats;
|
||||||
use time::precise_time_ns;
|
|
||||||
use getopts::{OptGroup, optflag, optopt};
|
use getopts::{OptGroup, optflag, optopt};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use serialize::{json, Decodable};
|
use serialize::{json, Decodable};
|
||||||
|
@ -53,8 +51,8 @@ use term::color::{Color, RED, YELLOW, GREEN, CYAN};
|
||||||
|
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::f64;
|
use std::f64;
|
||||||
use std::fmt;
|
|
||||||
use std::fmt::Show;
|
use std::fmt::Show;
|
||||||
|
use std::fmt;
|
||||||
use std::from_str::FromStr;
|
use std::from_str::FromStr;
|
||||||
use std::io::fs::PathExtensions;
|
use std::io::fs::PathExtensions;
|
||||||
use std::io::stdio::StdWriter;
|
use std::io::stdio::StdWriter;
|
||||||
|
@ -63,6 +61,7 @@ use std::io;
|
||||||
use std::os;
|
use std::os;
|
||||||
use std::string::String;
|
use std::string::String;
|
||||||
use std::task::TaskBuilder;
|
use std::task::TaskBuilder;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
// to be used by rustc to compile tests in libtest
|
// to be used by rustc to compile tests in libtest
|
||||||
pub mod test {
|
pub mod test {
|
||||||
|
@ -175,8 +174,7 @@ impl fmt::Show for TestFn {
|
||||||
/// call to `iter`.
|
/// call to `iter`.
|
||||||
pub struct Bencher {
|
pub struct Bencher {
|
||||||
iterations: u64,
|
iterations: u64,
|
||||||
ns_start: u64,
|
dur: Duration,
|
||||||
ns_end: u64,
|
|
||||||
pub bytes: u64,
|
pub bytes: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1322,20 +1320,16 @@ pub fn black_box<T>(dummy: T) {
|
||||||
impl Bencher {
|
impl Bencher {
|
||||||
/// Callback for benchmark functions to run in their body.
|
/// Callback for benchmark functions to run in their body.
|
||||||
pub fn iter<T>(&mut self, inner: || -> T) {
|
pub fn iter<T>(&mut self, inner: || -> T) {
|
||||||
self.ns_start = precise_time_ns();
|
self.dur = Duration::span(|| {
|
||||||
let k = self.iterations;
|
let k = self.iterations;
|
||||||
for _ in range(0u64, k) {
|
for _ in range(0u64, k) {
|
||||||
black_box(inner());
|
black_box(inner());
|
||||||
}
|
}
|
||||||
self.ns_end = precise_time_ns();
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ns_elapsed(&mut self) -> u64 {
|
pub fn ns_elapsed(&mut self) -> u64 {
|
||||||
if self.ns_start == 0 || self.ns_end == 0 {
|
self.dur.num_nanoseconds().unwrap() as u64
|
||||||
0
|
|
||||||
} else {
|
|
||||||
self.ns_end - self.ns_start
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ns_per_iter(&mut self) -> u64 {
|
pub fn ns_per_iter(&mut self) -> u64 {
|
||||||
|
@ -1372,41 +1366,44 @@ impl Bencher {
|
||||||
// (i.e. larger error bars).
|
// (i.e. larger error bars).
|
||||||
if n == 0 { n = 1; }
|
if n == 0 { n = 1; }
|
||||||
|
|
||||||
let mut total_run = 0;
|
let mut total_run = Duration::nanoseconds(0);
|
||||||
let samples : &mut [f64] = [0.0_f64, ..50];
|
let samples : &mut [f64] = [0.0_f64, ..50];
|
||||||
loop {
|
loop {
|
||||||
let loop_start = precise_time_ns();
|
let mut summ = None;
|
||||||
|
let mut summ5 = None;
|
||||||
|
|
||||||
for p in samples.iter_mut() {
|
let loop_run = Duration::span(|| {
|
||||||
self.bench_n(n, |x| f(x));
|
|
||||||
*p = self.ns_per_iter() as f64;
|
|
||||||
};
|
|
||||||
|
|
||||||
stats::winsorize(samples, 5.0);
|
for p in samples.iter_mut() {
|
||||||
let summ = stats::Summary::new(samples);
|
self.bench_n(n, |x| f(x));
|
||||||
|
*p = self.ns_per_iter() as f64;
|
||||||
|
};
|
||||||
|
|
||||||
for p in samples.iter_mut() {
|
stats::winsorize(samples, 5.0);
|
||||||
self.bench_n(5 * n, |x| f(x));
|
summ = Some(stats::Summary::new(samples));
|
||||||
*p = self.ns_per_iter() as f64;
|
|
||||||
};
|
|
||||||
|
|
||||||
stats::winsorize(samples, 5.0);
|
for p in samples.iter_mut() {
|
||||||
let summ5 = stats::Summary::new(samples);
|
self.bench_n(5 * n, |x| f(x));
|
||||||
|
*p = self.ns_per_iter() as f64;
|
||||||
|
};
|
||||||
|
|
||||||
let now = precise_time_ns();
|
stats::winsorize(samples, 5.0);
|
||||||
let loop_run = now - loop_start;
|
summ5 = Some(stats::Summary::new(samples));
|
||||||
|
});
|
||||||
|
let summ = summ.unwrap();
|
||||||
|
let summ5 = summ5.unwrap();
|
||||||
|
|
||||||
// If we've run for 100ms and seem to have converged to a
|
// If we've run for 100ms and seem to have converged to a
|
||||||
// stable median.
|
// stable median.
|
||||||
if loop_run > 100_000_000 &&
|
if loop_run.num_milliseconds() > 100 &&
|
||||||
summ.median_abs_dev_pct < 1.0 &&
|
summ.median_abs_dev_pct < 1.0 &&
|
||||||
summ.median - summ5.median < summ5.median_abs_dev {
|
summ.median - summ5.median < summ5.median_abs_dev {
|
||||||
return summ5;
|
return summ5;
|
||||||
}
|
}
|
||||||
|
|
||||||
total_run += loop_run;
|
total_run = total_run + loop_run;
|
||||||
// Longest we ever run for is 3s.
|
// Longest we ever run for is 3s.
|
||||||
if total_run > 3_000_000_000 {
|
if total_run.num_seconds() > 3 {
|
||||||
return summ5;
|
return summ5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1417,13 +1414,13 @@ impl Bencher {
|
||||||
|
|
||||||
pub mod bench {
|
pub mod bench {
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
|
use std::time::Duration;
|
||||||
use super::{Bencher, BenchSamples};
|
use super::{Bencher, BenchSamples};
|
||||||
|
|
||||||
pub fn benchmark(f: |&mut Bencher|) -> BenchSamples {
|
pub fn benchmark(f: |&mut Bencher|) -> BenchSamples {
|
||||||
let mut bs = Bencher {
|
let mut bs = Bencher {
|
||||||
iterations: 0,
|
iterations: 0,
|
||||||
ns_start: 0,
|
dur: Duration::nanoseconds(0),
|
||||||
ns_end: 0,
|
|
||||||
bytes: 0
|
bytes: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,8 @@
|
||||||
//! Simple time handling.
|
//! Simple time handling.
|
||||||
|
|
||||||
#![crate_name = "time"]
|
#![crate_name = "time"]
|
||||||
#![experimental]
|
#![deprecated = "use the http://github.com/rust-lang/time crate instead"]
|
||||||
|
#![allow(deprecated)]
|
||||||
|
|
||||||
#![crate_type = "rlib"]
|
#![crate_type = "rlib"]
|
||||||
#![crate_type = "dylib"]
|
#![crate_type = "dylib"]
|
||||||
|
|
11
src/test/auxiliary/lint-unused-extern-crate.rs
Normal file
11
src/test/auxiliary/lint-unused-extern-crate.rs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
// Copyright 2014 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.
|
||||||
|
|
||||||
|
pub fn foo() {}
|
|
@ -8,18 +8,14 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
extern crate time;
|
|
||||||
|
|
||||||
use std::collections::{TrieMap, TreeMap, HashMap, HashSet};
|
use std::collections::{TrieMap, TreeMap, HashMap, HashSet};
|
||||||
use std::os;
|
use std::os;
|
||||||
use std::rand::{Rng, IsaacRng, SeedableRng};
|
use std::rand::{Rng, IsaacRng, SeedableRng};
|
||||||
|
use std::time::Duration;
|
||||||
use std::uint;
|
use std::uint;
|
||||||
|
|
||||||
fn timed(label: &str, f: ||) {
|
fn timed(label: &str, f: ||) {
|
||||||
let start = time::precise_time_s();
|
println!(" {}: {}", label, Duration::span(f));
|
||||||
f();
|
|
||||||
let end = time::precise_time_s();
|
|
||||||
println!(" {}: {}", label, end - start);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
trait MutableMap {
|
trait MutableMap {
|
||||||
|
|
|
@ -12,30 +12,27 @@
|
||||||
|
|
||||||
extern crate collections;
|
extern crate collections;
|
||||||
extern crate rand;
|
extern crate rand;
|
||||||
extern crate time;
|
|
||||||
|
|
||||||
use std::collections::BitvSet;
|
use std::collections::BitvSet;
|
||||||
|
use std::collections::HashSet;
|
||||||
use std::collections::TreeSet;
|
use std::collections::TreeSet;
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
use std::collections::HashSet;
|
|
||||||
use std::os;
|
use std::os;
|
||||||
|
use std::time::Duration;
|
||||||
use std::uint;
|
use std::uint;
|
||||||
|
|
||||||
struct Results {
|
struct Results {
|
||||||
sequential_ints: f64,
|
sequential_ints: Duration,
|
||||||
random_ints: f64,
|
random_ints: Duration,
|
||||||
delete_ints: f64,
|
delete_ints: Duration,
|
||||||
|
|
||||||
sequential_strings: f64,
|
sequential_strings: Duration,
|
||||||
random_strings: f64,
|
random_strings: Duration,
|
||||||
delete_strings: f64
|
delete_strings: Duration,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn timed(result: &mut f64, op: ||) {
|
fn timed(result: &mut Duration, op: ||) {
|
||||||
let start = time::precise_time_s();
|
*result = Duration::span(op);
|
||||||
op();
|
|
||||||
let end = time::precise_time_s();
|
|
||||||
*result = (end - start);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
trait MutableSet<T> {
|
trait MutableSet<T> {
|
||||||
|
@ -150,7 +147,7 @@ fn write_header(header: &str) {
|
||||||
println!("{}", header);
|
println!("{}", header);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_row(label: &str, value: f64) {
|
fn write_row(label: &str, value: Duration) {
|
||||||
println!("{:30s} {} s\n", label, value);
|
println!("{:30s} {} s\n", label, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,13 +163,13 @@ fn write_results(label: &str, results: &Results) {
|
||||||
|
|
||||||
fn empty_results() -> Results {
|
fn empty_results() -> Results {
|
||||||
Results {
|
Results {
|
||||||
sequential_ints: 0.0,
|
sequential_ints: Duration::seconds(0),
|
||||||
random_ints: 0.0,
|
random_ints: Duration::seconds(0),
|
||||||
delete_ints: 0.0,
|
delete_ints: Duration::seconds(0),
|
||||||
|
|
||||||
sequential_strings: 0.0,
|
sequential_strings: Duration::seconds(0),
|
||||||
random_strings: 0.0,
|
random_strings: Duration::seconds(0),
|
||||||
delete_strings: 0.0,
|
delete_strings: Duration::seconds(0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,16 +13,14 @@
|
||||||
|
|
||||||
#![feature(macro_rules)]
|
#![feature(macro_rules)]
|
||||||
|
|
||||||
extern crate time;
|
use std::io::File;
|
||||||
|
|
||||||
use time::precise_time_s;
|
|
||||||
use std::rand;
|
|
||||||
use std::rand::Rng;
|
|
||||||
use std::mem::swap;
|
use std::mem::swap;
|
||||||
use std::os;
|
use std::os;
|
||||||
|
use std::rand::Rng;
|
||||||
|
use std::rand;
|
||||||
use std::str;
|
use std::str;
|
||||||
|
use std::time::Duration;
|
||||||
use std::vec;
|
use std::vec;
|
||||||
use std::io::File;
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let argv = os::args();
|
let argv = os::args();
|
||||||
|
@ -56,11 +54,9 @@ fn maybe_run_test(argv: &[String], name: String, test: ||) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let start = precise_time_s();
|
let dur = Duration::span(test);
|
||||||
test();
|
|
||||||
let stop = precise_time_s();
|
|
||||||
|
|
||||||
println!("{}:\t\t{} ms", name, (stop - start) * 1000.0);
|
println!("{}:\t\t{} ms", name, dur.num_milliseconds());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn shift_push() {
|
fn shift_push() {
|
||||||
|
|
|
@ -18,11 +18,10 @@
|
||||||
// different scalability characteristics compared to the select
|
// different scalability characteristics compared to the select
|
||||||
// version.
|
// version.
|
||||||
|
|
||||||
extern crate time;
|
|
||||||
|
|
||||||
use std::comm;
|
use std::comm;
|
||||||
use std::os;
|
use std::os;
|
||||||
use std::task;
|
use std::task;
|
||||||
|
use std::time::Duration;
|
||||||
use std::uint;
|
use std::uint;
|
||||||
|
|
||||||
fn move_out<T>(_x: T) {}
|
fn move_out<T>(_x: T) {}
|
||||||
|
@ -58,36 +57,39 @@ fn run(args: &[String]) {
|
||||||
let size = from_str::<uint>(args[1].as_slice()).unwrap();
|
let size = from_str::<uint>(args[1].as_slice()).unwrap();
|
||||||
let workers = from_str::<uint>(args[2].as_slice()).unwrap();
|
let workers = from_str::<uint>(args[2].as_slice()).unwrap();
|
||||||
let num_bytes = 100;
|
let num_bytes = 100;
|
||||||
let start = time::precise_time_s();
|
let mut result = None;
|
||||||
let mut worker_results = Vec::new();
|
let mut p = Some((to_child, to_parent, from_parent));
|
||||||
for _ in range(0u, workers) {
|
let dur = Duration::span(|| {
|
||||||
let to_child = to_child.clone();
|
let (to_child, to_parent, from_parent) = p.take().unwrap();
|
||||||
worker_results.push(task::try_future(proc() {
|
let mut worker_results = Vec::new();
|
||||||
for _ in range(0u, size / workers) {
|
for _ in range(0u, workers) {
|
||||||
//println!("worker {}: sending {} bytes", i, num_bytes);
|
let to_child = to_child.clone();
|
||||||
to_child.send(bytes(num_bytes));
|
worker_results.push(task::try_future(proc() {
|
||||||
}
|
for _ in range(0u, size / workers) {
|
||||||
//println!("worker {} exiting", i);
|
//println!("worker {}: sending {} bytes", i, num_bytes);
|
||||||
}));
|
to_child.send(bytes(num_bytes));
|
||||||
}
|
}
|
||||||
task::spawn(proc() {
|
//println!("worker {} exiting", i);
|
||||||
server(&from_parent, &to_parent);
|
}));
|
||||||
|
}
|
||||||
|
task::spawn(proc() {
|
||||||
|
server(&from_parent, &to_parent);
|
||||||
|
});
|
||||||
|
|
||||||
|
for r in worker_results.into_iter() {
|
||||||
|
r.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
//println!("sending stop message");
|
||||||
|
to_child.send(stop);
|
||||||
|
move_out(to_child);
|
||||||
|
result = Some(from_child.recv());
|
||||||
});
|
});
|
||||||
|
let result = result.unwrap();
|
||||||
for r in worker_results.into_iter() {
|
|
||||||
r.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
//println!("sending stop message");
|
|
||||||
to_child.send(stop);
|
|
||||||
move_out(to_child);
|
|
||||||
let result = from_child.recv();
|
|
||||||
let end = time::precise_time_s();
|
|
||||||
let elapsed = end - start;
|
|
||||||
print!("Count is {}\n", result);
|
print!("Count is {}\n", result);
|
||||||
print!("Test took {} seconds\n", elapsed);
|
print!("Test took {} ms\n", dur.num_milliseconds());
|
||||||
let thruput = ((size / workers * workers) as f64) / (elapsed as f64);
|
let thruput = ((size / workers * workers) as f64) / (dur.num_milliseconds() as f64);
|
||||||
print!("Throughput={} per sec\n", thruput);
|
print!("Throughput={} per sec\n", thruput / 1000.0);
|
||||||
assert_eq!(result, num_bytes * size);
|
assert_eq!(result, num_bytes * size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,10 +14,9 @@
|
||||||
//
|
//
|
||||||
// I *think* it's the same, more or less.
|
// I *think* it's the same, more or less.
|
||||||
|
|
||||||
extern crate time;
|
|
||||||
|
|
||||||
use std::os;
|
use std::os;
|
||||||
use std::task;
|
use std::task;
|
||||||
|
use std::time::Duration;
|
||||||
use std::uint;
|
use std::uint;
|
||||||
|
|
||||||
fn move_out<T>(_x: T) {}
|
fn move_out<T>(_x: T) {}
|
||||||
|
@ -52,22 +51,13 @@ fn run(args: &[String]) {
|
||||||
let size = from_str::<uint>(args[1].as_slice()).unwrap();
|
let size = from_str::<uint>(args[1].as_slice()).unwrap();
|
||||||
let workers = from_str::<uint>(args[2].as_slice()).unwrap();
|
let workers = from_str::<uint>(args[2].as_slice()).unwrap();
|
||||||
let num_bytes = 100;
|
let num_bytes = 100;
|
||||||
let start = time::precise_time_s();
|
let mut result = None;
|
||||||
let mut worker_results = Vec::new();
|
let mut to_parent = Some(to_parent);
|
||||||
let from_parent = if workers == 1 {
|
let dur = Duration::span(|| {
|
||||||
let (to_child, from_parent) = channel();
|
let to_parent = to_parent.take().unwrap();
|
||||||
worker_results.push(task::try_future(proc() {
|
let mut worker_results = Vec::new();
|
||||||
for _ in range(0u, size / workers) {
|
let from_parent = if workers == 1 {
|
||||||
//println!("worker {}: sending {} bytes", i, num_bytes);
|
let (to_child, from_parent) = channel();
|
||||||
to_child.send(bytes(num_bytes));
|
|
||||||
}
|
|
||||||
//println!("worker {} exiting", i);
|
|
||||||
}));
|
|
||||||
from_parent
|
|
||||||
} else {
|
|
||||||
let (to_child, from_parent) = channel();
|
|
||||||
for _ in range(0u, workers) {
|
|
||||||
let to_child = to_child.clone();
|
|
||||||
worker_results.push(task::try_future(proc() {
|
worker_results.push(task::try_future(proc() {
|
||||||
for _ in range(0u, size / workers) {
|
for _ in range(0u, size / workers) {
|
||||||
//println!("worker {}: sending {} bytes", i, num_bytes);
|
//println!("worker {}: sending {} bytes", i, num_bytes);
|
||||||
|
@ -75,27 +65,39 @@ fn run(args: &[String]) {
|
||||||
}
|
}
|
||||||
//println!("worker {} exiting", i);
|
//println!("worker {} exiting", i);
|
||||||
}));
|
}));
|
||||||
|
from_parent
|
||||||
|
} else {
|
||||||
|
let (to_child, from_parent) = channel();
|
||||||
|
for _ in range(0u, workers) {
|
||||||
|
let to_child = to_child.clone();
|
||||||
|
worker_results.push(task::try_future(proc() {
|
||||||
|
for _ in range(0u, size / workers) {
|
||||||
|
//println!("worker {}: sending {} bytes", i, num_bytes);
|
||||||
|
to_child.send(bytes(num_bytes));
|
||||||
|
}
|
||||||
|
//println!("worker {} exiting", i);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
from_parent
|
||||||
|
};
|
||||||
|
task::spawn(proc() {
|
||||||
|
server(&from_parent, &to_parent);
|
||||||
|
});
|
||||||
|
|
||||||
|
for r in worker_results.into_iter() {
|
||||||
|
r.unwrap();
|
||||||
}
|
}
|
||||||
from_parent
|
|
||||||
};
|
//println!("sending stop message");
|
||||||
task::spawn(proc() {
|
//to_child.send(stop);
|
||||||
server(&from_parent, &to_parent);
|
//move_out(to_child);
|
||||||
|
result = Some(from_child.recv());
|
||||||
});
|
});
|
||||||
|
let result = result.unwrap();
|
||||||
for r in worker_results.into_iter() {
|
|
||||||
r.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
//println!("sending stop message");
|
|
||||||
//to_child.send(stop);
|
|
||||||
//move_out(to_child);
|
|
||||||
let result = from_child.recv();
|
|
||||||
let end = time::precise_time_s();
|
|
||||||
let elapsed = end - start;
|
|
||||||
print!("Count is {}\n", result);
|
print!("Count is {}\n", result);
|
||||||
print!("Test took {} seconds\n", elapsed);
|
print!("Test took {} ms\n", dur.num_milliseconds());
|
||||||
let thruput = ((size / workers * workers) as f64) / (elapsed as f64);
|
let thruput = ((size / workers * workers) as f64) / (dur.num_milliseconds() as f64);
|
||||||
print!("Throughput={} per sec\n", thruput);
|
print!("Throughput={} per sec\n", thruput / 1000.0);
|
||||||
assert_eq!(result, num_bytes * size);
|
assert_eq!(result, num_bytes * size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,10 +18,9 @@
|
||||||
// no-pretty-expanded FIXME #15189
|
// no-pretty-expanded FIXME #15189
|
||||||
// ignore-lexer-test FIXME #15679
|
// ignore-lexer-test FIXME #15679
|
||||||
|
|
||||||
extern crate time;
|
|
||||||
|
|
||||||
use std::sync::{Arc, Future, Mutex};
|
|
||||||
use std::os;
|
use std::os;
|
||||||
|
use std::sync::{Arc, Future, Mutex};
|
||||||
|
use std::time::Duration;
|
||||||
use std::uint;
|
use std::uint;
|
||||||
|
|
||||||
// A poor man's pipe.
|
// A poor man's pipe.
|
||||||
|
@ -77,38 +76,38 @@ fn main() {
|
||||||
|
|
||||||
let (mut num_chan, num_port) = init();
|
let (mut num_chan, num_port) = init();
|
||||||
|
|
||||||
let start = time::precise_time_s();
|
let mut p = Some((num_chan, num_port));
|
||||||
|
let dur = Duration::span(|| {
|
||||||
|
let (mut num_chan, num_port) = p.take().unwrap();
|
||||||
|
|
||||||
// create the ring
|
// create the ring
|
||||||
let mut futures = Vec::new();
|
let mut futures = Vec::new();
|
||||||
|
|
||||||
for i in range(1u, num_tasks) {
|
for i in range(1u, num_tasks) {
|
||||||
//println!("spawning %?", i);
|
//println!("spawning %?", i);
|
||||||
let (new_chan, num_port) = init();
|
let (new_chan, num_port) = init();
|
||||||
let num_chan_2 = num_chan.clone();
|
let num_chan_2 = num_chan.clone();
|
||||||
let new_future = Future::spawn(proc() {
|
let new_future = Future::spawn(proc() {
|
||||||
thread_ring(i, msg_per_task, num_chan_2, num_port)
|
thread_ring(i, msg_per_task, num_chan_2, num_port)
|
||||||
});
|
});
|
||||||
futures.push(new_future);
|
futures.push(new_future);
|
||||||
num_chan = new_chan;
|
num_chan = new_chan;
|
||||||
};
|
};
|
||||||
|
|
||||||
// do our iteration
|
// do our iteration
|
||||||
thread_ring(0, msg_per_task, num_chan, num_port);
|
thread_ring(0, msg_per_task, num_chan, num_port);
|
||||||
|
|
||||||
// synchronize
|
// synchronize
|
||||||
for f in futures.iter_mut() {
|
for f in futures.iter_mut() {
|
||||||
f.get()
|
f.get()
|
||||||
}
|
}
|
||||||
|
});
|
||||||
let stop = time::precise_time_s();
|
|
||||||
|
|
||||||
// all done, report stats.
|
// all done, report stats.
|
||||||
let num_msgs = num_tasks * msg_per_task;
|
let num_msgs = num_tasks * msg_per_task;
|
||||||
let elapsed = (stop - start);
|
let rate = (num_msgs as f64) / (dur.num_milliseconds() as f64);
|
||||||
let rate = (num_msgs as f64) / elapsed;
|
|
||||||
|
|
||||||
println!("Sent {} messages in {} seconds", num_msgs, elapsed);
|
println!("Sent {} messages in {} ms", num_msgs, dur.num_milliseconds());
|
||||||
println!(" {} messages / second", rate);
|
println!(" {} messages / second", rate / 1000.0);
|
||||||
println!(" {} μs / message", 1000000. / rate);
|
println!(" {} μs / message", 1000000. / rate / 1000.0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,10 +18,9 @@
|
||||||
// no-pretty-expanded FIXME #15189
|
// no-pretty-expanded FIXME #15189
|
||||||
// ignore-lexer-test FIXME #15679
|
// ignore-lexer-test FIXME #15679
|
||||||
|
|
||||||
extern crate time;
|
|
||||||
|
|
||||||
use std::sync::{RWLock, Arc, Future};
|
|
||||||
use std::os;
|
use std::os;
|
||||||
|
use std::sync::{RWLock, Arc, Future};
|
||||||
|
use std::time::Duration;
|
||||||
use std::uint;
|
use std::uint;
|
||||||
|
|
||||||
// A poor man's pipe.
|
// A poor man's pipe.
|
||||||
|
@ -77,38 +76,38 @@ fn main() {
|
||||||
|
|
||||||
let (mut num_chan, num_port) = init();
|
let (mut num_chan, num_port) = init();
|
||||||
|
|
||||||
let start = time::precise_time_s();
|
let mut p = Some((num_chan, num_port));
|
||||||
|
let dur = Duration::span(|| {
|
||||||
|
let (mut num_chan, num_port) = p.take().unwrap();
|
||||||
|
|
||||||
// create the ring
|
// create the ring
|
||||||
let mut futures = Vec::new();
|
let mut futures = Vec::new();
|
||||||
|
|
||||||
for i in range(1u, num_tasks) {
|
for i in range(1u, num_tasks) {
|
||||||
//println!("spawning %?", i);
|
//println!("spawning %?", i);
|
||||||
let (new_chan, num_port) = init();
|
let (new_chan, num_port) = init();
|
||||||
let num_chan_2 = num_chan.clone();
|
let num_chan_2 = num_chan.clone();
|
||||||
let new_future = Future::spawn(proc() {
|
let new_future = Future::spawn(proc() {
|
||||||
thread_ring(i, msg_per_task, num_chan_2, num_port)
|
thread_ring(i, msg_per_task, num_chan_2, num_port)
|
||||||
});
|
});
|
||||||
futures.push(new_future);
|
futures.push(new_future);
|
||||||
num_chan = new_chan;
|
num_chan = new_chan;
|
||||||
};
|
};
|
||||||
|
|
||||||
// do our iteration
|
// do our iteration
|
||||||
thread_ring(0, msg_per_task, num_chan, num_port);
|
thread_ring(0, msg_per_task, num_chan, num_port);
|
||||||
|
|
||||||
// synchronize
|
// synchronize
|
||||||
for f in futures.iter_mut() {
|
for f in futures.iter_mut() {
|
||||||
let _ = f.get();
|
let _ = f.get();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
let stop = time::precise_time_s();
|
|
||||||
|
|
||||||
// all done, report stats.
|
// all done, report stats.
|
||||||
let num_msgs = num_tasks * msg_per_task;
|
let num_msgs = num_tasks * msg_per_task;
|
||||||
let elapsed = (stop - start);
|
let rate = (num_msgs as f64) / (dur.num_milliseconds() as f64);
|
||||||
let rate = (num_msgs as f64) / elapsed;
|
|
||||||
|
|
||||||
println!("Sent {} messages in {} seconds", num_msgs, elapsed);
|
println!("Sent {} messages in {} ms", num_msgs, dur.num_milliseconds());
|
||||||
println!(" {} messages / second", rate);
|
println!(" {} messages / second", rate / 1000.0);
|
||||||
println!(" {} μs / message", 1000000. / rate);
|
println!(" {} μs / message", 1000000. / rate / 1000.0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,11 +19,11 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
extern crate time;
|
|
||||||
|
|
||||||
use std::os;
|
use std::os;
|
||||||
use std::result::{Ok, Err};
|
use std::result::{Ok, Err};
|
||||||
use std::task;
|
use std::task;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
fn fib(n: int) -> int {
|
fn fib(n: int) -> int {
|
||||||
fn pfib(tx: &Sender<int>, n: int) {
|
fn pfib(tx: &Sender<int>, n: int) {
|
||||||
|
@ -107,13 +107,11 @@ fn main() {
|
||||||
|
|
||||||
for n in range(1, max + 1) {
|
for n in range(1, max + 1) {
|
||||||
for _ in range(0u, num_trials) {
|
for _ in range(0u, num_trials) {
|
||||||
let start = time::precise_time_ns();
|
let mut fibn = None;
|
||||||
let fibn = fib(n);
|
let dur = Duration::span(|| fibn = Some(fib(n)));
|
||||||
let stop = time::precise_time_ns();
|
let fibn = fibn.unwrap();
|
||||||
|
|
||||||
let elapsed = stop - start;
|
println!("{}\t{}\t{}", n, fibn, dur);
|
||||||
|
|
||||||
println!("{}\t{}\t{}", n, fibn, elapsed.to_string());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,11 +10,9 @@
|
||||||
|
|
||||||
// Microbenchmark for the smallintmap library
|
// Microbenchmark for the smallintmap library
|
||||||
|
|
||||||
extern crate collections;
|
|
||||||
extern crate time;
|
|
||||||
|
|
||||||
use std::collections::VecMap;
|
use std::collections::VecMap;
|
||||||
use std::os;
|
use std::os;
|
||||||
|
use std::time::Duration;
|
||||||
use std::uint;
|
use std::uint;
|
||||||
|
|
||||||
fn append_sequential(min: uint, max: uint, map: &mut VecMap<uint>) {
|
fn append_sequential(min: uint, max: uint, map: &mut VecMap<uint>) {
|
||||||
|
@ -41,25 +39,22 @@ fn main() {
|
||||||
let max = from_str::<uint>(args[1].as_slice()).unwrap();
|
let max = from_str::<uint>(args[1].as_slice()).unwrap();
|
||||||
let rep = from_str::<uint>(args[2].as_slice()).unwrap();
|
let rep = from_str::<uint>(args[2].as_slice()).unwrap();
|
||||||
|
|
||||||
let mut checkf = 0.0;
|
let mut checkf = Duration::seconds(0);
|
||||||
let mut appendf = 0.0;
|
let mut appendf = Duration::seconds(0);
|
||||||
|
|
||||||
for _ in range(0u, rep) {
|
for _ in range(0u, rep) {
|
||||||
let mut map = VecMap::new();
|
let mut map = VecMap::new();
|
||||||
let start = time::precise_time_s();
|
let d1 = Duration::span(|| append_sequential(0u, max, &mut map));
|
||||||
append_sequential(0u, max, &mut map);
|
let d2 = Duration::span(|| check_sequential(0u, max, &map));
|
||||||
let mid = time::precise_time_s();
|
|
||||||
check_sequential(0u, max, &map);
|
|
||||||
let end = time::precise_time_s();
|
|
||||||
|
|
||||||
checkf += (end - mid) as f64;
|
checkf = checkf + d2;
|
||||||
appendf += (mid - start) as f64;
|
appendf = appendf + d1;
|
||||||
}
|
}
|
||||||
|
|
||||||
let maxf = max as f64;
|
let maxf = max as f64;
|
||||||
|
|
||||||
println!("insert(): {} seconds\n", checkf);
|
println!("insert(): {} seconds\n", checkf);
|
||||||
println!(" : {} op/sec\n", maxf/checkf);
|
println!(" : {} op/ms\n", maxf / checkf.num_milliseconds() as f64);
|
||||||
println!("get() : {} seconds\n", appendf);
|
println!("get() : {} seconds\n", appendf);
|
||||||
println!(" : {} op/sec\n", maxf/appendf);
|
println!(" : {} op/ms\n", maxf / appendf.num_milliseconds() as f64);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,11 +10,9 @@
|
||||||
|
|
||||||
#![feature(unsafe_destructor)]
|
#![feature(unsafe_destructor)]
|
||||||
|
|
||||||
extern crate time;
|
|
||||||
|
|
||||||
use time::precise_time_s;
|
|
||||||
use std::os;
|
use std::os;
|
||||||
use std::task;
|
use std::task;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
#[deriving(Clone)]
|
#[deriving(Clone)]
|
||||||
enum List<T> {
|
enum List<T> {
|
||||||
|
@ -37,11 +35,12 @@ fn main() {
|
||||||
|
|
||||||
fn run(repeat: int, depth: int) {
|
fn run(repeat: int, depth: int) {
|
||||||
for _ in range(0, repeat) {
|
for _ in range(0, repeat) {
|
||||||
println!("starting {:.4f}", precise_time_s());
|
let dur = Duration::span(|| {
|
||||||
task::try(proc() {
|
task::try(proc() {
|
||||||
recurse_or_panic(depth, None)
|
recurse_or_panic(depth, None)
|
||||||
|
});
|
||||||
});
|
});
|
||||||
println!("stopping {:.4f}", precise_time_s());
|
println!("iter: {}", dur);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +71,6 @@ fn r(l: Box<nillist>) -> r {
|
||||||
|
|
||||||
fn recurse_or_panic(depth: int, st: Option<State>) {
|
fn recurse_or_panic(depth: int, st: Option<State>) {
|
||||||
if depth == 0 {
|
if depth == 0 {
|
||||||
println!("unwinding {:.4f}", precise_time_s());
|
|
||||||
panic!();
|
panic!();
|
||||||
} else {
|
} else {
|
||||||
let depth = depth - 1;
|
let depth = depth - 1;
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
// aux-build:lint-unused-extern-crate.rs
|
||||||
|
|
||||||
#![feature(globs)]
|
#![feature(globs)]
|
||||||
#![deny(unused_extern_crates)]
|
#![deny(unused_extern_crates)]
|
||||||
#![allow(unused_variables)]
|
#![allow(unused_variables)]
|
||||||
|
@ -19,14 +21,14 @@ extern crate "collections" as collecs; // no error, it is used
|
||||||
extern crate rand; // no error, the use marks it as used
|
extern crate rand; // no error, the use marks it as used
|
||||||
// even if imported objects aren't used
|
// even if imported objects aren't used
|
||||||
|
|
||||||
extern crate time; // no error, the use * marks it as used
|
extern crate "lint-unused-extern-crate" as other; // no error, the use * marks it as used
|
||||||
|
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use rand::isaac::IsaacRng;
|
use rand::isaac::IsaacRng;
|
||||||
|
|
||||||
use time::*;
|
use other::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x: collecs::vec::Vec<uint> = Vec::new();
|
let x: collecs::vec::Vec<uint> = Vec::new();
|
||||||
let y = now();
|
let y = foo();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue