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:
Alex Crichton 2014-11-10 12:27:56 -08:00
parent e4ead7b034
commit fcd05ed99f
22 changed files with 329 additions and 266 deletions

View 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() {}

View file

@ -8,18 +8,14 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate time;
use std::collections::{TrieMap, TreeMap, HashMap, HashSet};
use std::os;
use std::rand::{Rng, IsaacRng, SeedableRng};
use std::time::Duration;
use std::uint;
fn timed(label: &str, f: ||) {
let start = time::precise_time_s();
f();
let end = time::precise_time_s();
println!(" {}: {}", label, end - start);
println!(" {}: {}", label, Duration::span(f));
}
trait MutableMap {

View file

@ -12,30 +12,27 @@
extern crate collections;
extern crate rand;
extern crate time;
use std::collections::BitvSet;
use std::collections::HashSet;
use std::collections::TreeSet;
use std::hash::Hash;
use std::collections::HashSet;
use std::os;
use std::time::Duration;
use std::uint;
struct Results {
sequential_ints: f64,
random_ints: f64,
delete_ints: f64,
sequential_ints: Duration,
random_ints: Duration,
delete_ints: Duration,
sequential_strings: f64,
random_strings: f64,
delete_strings: f64
sequential_strings: Duration,
random_strings: Duration,
delete_strings: Duration,
}
fn timed(result: &mut f64, op: ||) {
let start = time::precise_time_s();
op();
let end = time::precise_time_s();
*result = (end - start);
fn timed(result: &mut Duration, op: ||) {
*result = Duration::span(op);
}
trait MutableSet<T> {
@ -150,7 +147,7 @@ fn write_header(header: &str) {
println!("{}", header);
}
fn write_row(label: &str, value: f64) {
fn write_row(label: &str, value: Duration) {
println!("{:30s} {} s\n", label, value);
}
@ -166,13 +163,13 @@ fn write_results(label: &str, results: &Results) {
fn empty_results() -> Results {
Results {
sequential_ints: 0.0,
random_ints: 0.0,
delete_ints: 0.0,
sequential_ints: Duration::seconds(0),
random_ints: Duration::seconds(0),
delete_ints: Duration::seconds(0),
sequential_strings: 0.0,
random_strings: 0.0,
delete_strings: 0.0,
sequential_strings: Duration::seconds(0),
random_strings: Duration::seconds(0),
delete_strings: Duration::seconds(0),
}
}

View file

@ -13,16 +13,14 @@
#![feature(macro_rules)]
extern crate time;
use time::precise_time_s;
use std::rand;
use std::rand::Rng;
use std::io::File;
use std::mem::swap;
use std::os;
use std::rand::Rng;
use std::rand;
use std::str;
use std::time::Duration;
use std::vec;
use std::io::File;
fn main() {
let argv = os::args();
@ -56,11 +54,9 @@ fn maybe_run_test(argv: &[String], name: String, test: ||) {
return
}
let start = precise_time_s();
test();
let stop = precise_time_s();
let dur = Duration::span(test);
println!("{}:\t\t{} ms", name, (stop - start) * 1000.0);
println!("{}:\t\t{} ms", name, dur.num_milliseconds());
}
fn shift_push() {

View file

@ -18,11 +18,10 @@
// different scalability characteristics compared to the select
// version.
extern crate time;
use std::comm;
use std::os;
use std::task;
use std::time::Duration;
use std::uint;
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 workers = from_str::<uint>(args[2].as_slice()).unwrap();
let num_bytes = 100;
let start = time::precise_time_s();
let mut worker_results = Vec::new();
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);
}));
}
task::spawn(proc() {
server(&from_parent, &to_parent);
let mut result = None;
let mut p = Some((to_child, to_parent, from_parent));
let dur = Duration::span(|| {
let (to_child, to_parent, from_parent) = p.take().unwrap();
let mut worker_results = Vec::new();
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);
}));
}
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());
});
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;
let result = result.unwrap();
print!("Count is {}\n", result);
print!("Test took {} seconds\n", elapsed);
let thruput = ((size / workers * workers) as f64) / (elapsed as f64);
print!("Throughput={} per sec\n", thruput);
print!("Test took {} ms\n", dur.num_milliseconds());
let thruput = ((size / workers * workers) as f64) / (dur.num_milliseconds() as f64);
print!("Throughput={} per sec\n", thruput / 1000.0);
assert_eq!(result, num_bytes * size);
}

View file

@ -14,10 +14,9 @@
//
// I *think* it's the same, more or less.
extern crate time;
use std::os;
use std::task;
use std::time::Duration;
use std::uint;
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 workers = from_str::<uint>(args[2].as_slice()).unwrap();
let num_bytes = 100;
let start = time::precise_time_s();
let mut worker_results = Vec::new();
let from_parent = if workers == 1 {
let (to_child, from_parent) = channel();
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
} else {
let (to_child, from_parent) = channel();
for _ in range(0u, workers) {
let to_child = to_child.clone();
let mut result = None;
let mut to_parent = Some(to_parent);
let dur = Duration::span(|| {
let to_parent = to_parent.take().unwrap();
let mut worker_results = Vec::new();
let from_parent = if workers == 1 {
let (to_child, from_parent) = channel();
worker_results.push(task::try_future(proc() {
for _ in range(0u, size / workers) {
//println!("worker {}: sending {} bytes", i, num_bytes);
@ -75,27 +65,39 @@ fn run(args: &[String]) {
}
//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
};
task::spawn(proc() {
server(&from_parent, &to_parent);
//println!("sending stop message");
//to_child.send(stop);
//move_out(to_child);
result = Some(from_child.recv());
});
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;
let result = result.unwrap();
print!("Count is {}\n", result);
print!("Test took {} seconds\n", elapsed);
let thruput = ((size / workers * workers) as f64) / (elapsed as f64);
print!("Throughput={} per sec\n", thruput);
print!("Test took {} ms\n", dur.num_milliseconds());
let thruput = ((size / workers * workers) as f64) / (dur.num_milliseconds() as f64);
print!("Throughput={} per sec\n", thruput / 1000.0);
assert_eq!(result, num_bytes * size);
}

View file

@ -18,10 +18,9 @@
// no-pretty-expanded FIXME #15189
// ignore-lexer-test FIXME #15679
extern crate time;
use std::sync::{Arc, Future, Mutex};
use std::os;
use std::sync::{Arc, Future, Mutex};
use std::time::Duration;
use std::uint;
// A poor man's pipe.
@ -77,38 +76,38 @@ fn main() {
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
let mut futures = Vec::new();
// create the ring
let mut futures = Vec::new();
for i in range(1u, num_tasks) {
//println!("spawning %?", i);
let (new_chan, num_port) = init();
let num_chan_2 = num_chan.clone();
let new_future = Future::spawn(proc() {
thread_ring(i, msg_per_task, num_chan_2, num_port)
});
futures.push(new_future);
num_chan = new_chan;
};
for i in range(1u, num_tasks) {
//println!("spawning %?", i);
let (new_chan, num_port) = init();
let num_chan_2 = num_chan.clone();
let new_future = Future::spawn(proc() {
thread_ring(i, msg_per_task, num_chan_2, num_port)
});
futures.push(new_future);
num_chan = new_chan;
};
// do our iteration
thread_ring(0, msg_per_task, num_chan, num_port);
// do our iteration
thread_ring(0, msg_per_task, num_chan, num_port);
// synchronize
for f in futures.iter_mut() {
f.get()
}
let stop = time::precise_time_s();
// synchronize
for f in futures.iter_mut() {
f.get()
}
});
// all done, report stats.
let num_msgs = num_tasks * msg_per_task;
let elapsed = (stop - start);
let rate = (num_msgs as f64) / elapsed;
let rate = (num_msgs as f64) / (dur.num_milliseconds() as f64);
println!("Sent {} messages in {} seconds", num_msgs, elapsed);
println!(" {} messages / second", rate);
println!(" {} μs / message", 1000000. / rate);
println!("Sent {} messages in {} ms", num_msgs, dur.num_milliseconds());
println!(" {} messages / second", rate / 1000.0);
println!(" {} μs / message", 1000000. / rate / 1000.0);
}

View file

@ -18,10 +18,9 @@
// no-pretty-expanded FIXME #15189
// ignore-lexer-test FIXME #15679
extern crate time;
use std::sync::{RWLock, Arc, Future};
use std::os;
use std::sync::{RWLock, Arc, Future};
use std::time::Duration;
use std::uint;
// A poor man's pipe.
@ -77,38 +76,38 @@ fn main() {
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
let mut futures = Vec::new();
// create the ring
let mut futures = Vec::new();
for i in range(1u, num_tasks) {
//println!("spawning %?", i);
let (new_chan, num_port) = init();
let num_chan_2 = num_chan.clone();
let new_future = Future::spawn(proc() {
thread_ring(i, msg_per_task, num_chan_2, num_port)
});
futures.push(new_future);
num_chan = new_chan;
};
for i in range(1u, num_tasks) {
//println!("spawning %?", i);
let (new_chan, num_port) = init();
let num_chan_2 = num_chan.clone();
let new_future = Future::spawn(proc() {
thread_ring(i, msg_per_task, num_chan_2, num_port)
});
futures.push(new_future);
num_chan = new_chan;
};
// do our iteration
thread_ring(0, msg_per_task, num_chan, num_port);
// do our iteration
thread_ring(0, msg_per_task, num_chan, num_port);
// synchronize
for f in futures.iter_mut() {
let _ = f.get();
}
let stop = time::precise_time_s();
// synchronize
for f in futures.iter_mut() {
let _ = f.get();
}
});
// all done, report stats.
let num_msgs = num_tasks * msg_per_task;
let elapsed = (stop - start);
let rate = (num_msgs as f64) / elapsed;
let rate = (num_msgs as f64) / (dur.num_milliseconds() as f64);
println!("Sent {} messages in {} seconds", num_msgs, elapsed);
println!(" {} messages / second", rate);
println!(" {} μs / message", 1000000. / rate);
println!("Sent {} messages in {} ms", num_msgs, dur.num_milliseconds());
println!(" {} messages / second", rate / 1000.0);
println!(" {} μs / message", 1000000. / rate / 1000.0);
}

View file

@ -19,11 +19,11 @@
*/
extern crate getopts;
extern crate time;
use std::os;
use std::result::{Ok, Err};
use std::task;
use std::time::Duration;
fn fib(n: int) -> int {
fn pfib(tx: &Sender<int>, n: int) {
@ -107,13 +107,11 @@ fn main() {
for n in range(1, max + 1) {
for _ in range(0u, num_trials) {
let start = time::precise_time_ns();
let fibn = fib(n);
let stop = time::precise_time_ns();
let mut fibn = None;
let dur = Duration::span(|| fibn = Some(fib(n)));
let fibn = fibn.unwrap();
let elapsed = stop - start;
println!("{}\t{}\t{}", n, fibn, elapsed.to_string());
println!("{}\t{}\t{}", n, fibn, dur);
}
}
}

View file

@ -10,11 +10,9 @@
// Microbenchmark for the smallintmap library
extern crate collections;
extern crate time;
use std::collections::VecMap;
use std::os;
use std::time::Duration;
use std::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 rep = from_str::<uint>(args[2].as_slice()).unwrap();
let mut checkf = 0.0;
let mut appendf = 0.0;
let mut checkf = Duration::seconds(0);
let mut appendf = Duration::seconds(0);
for _ in range(0u, rep) {
let mut map = VecMap::new();
let start = time::precise_time_s();
append_sequential(0u, max, &mut map);
let mid = time::precise_time_s();
check_sequential(0u, max, &map);
let end = time::precise_time_s();
let d1 = Duration::span(|| append_sequential(0u, max, &mut map));
let d2 = Duration::span(|| check_sequential(0u, max, &map));
checkf += (end - mid) as f64;
appendf += (mid - start) as f64;
checkf = checkf + d2;
appendf = appendf + d1;
}
let maxf = max as f64;
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!(" : {} op/sec\n", maxf/appendf);
println!(" : {} op/ms\n", maxf / appendf.num_milliseconds() as f64);
}

View file

@ -10,11 +10,9 @@
#![feature(unsafe_destructor)]
extern crate time;
use time::precise_time_s;
use std::os;
use std::task;
use std::time::Duration;
#[deriving(Clone)]
enum List<T> {
@ -37,11 +35,12 @@ fn main() {
fn run(repeat: int, depth: int) {
for _ in range(0, repeat) {
println!("starting {:.4f}", precise_time_s());
task::try(proc() {
recurse_or_panic(depth, None)
let dur = Duration::span(|| {
task::try(proc() {
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>) {
if depth == 0 {
println!("unwinding {:.4f}", precise_time_s());
panic!();
} else {
let depth = depth - 1;

View file

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:lint-unused-extern-crate.rs
#![feature(globs)]
#![deny(unused_extern_crates)]
#![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
// 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)]
use rand::isaac::IsaacRng;
use time::*;
use other::*;
fn main() {
let x: collecs::vec::Vec<uint> = Vec::new();
let y = now();
let y = foo();
}