Skip to content

Commit 53492ec

Browse files
committed
Remove the deprecated Duration::span
… so that Duration can be moved into libcore. The removal will hit stable in 1.7 at the soonest, while 1.6 already has the deprecation warning.
1 parent a06bb97 commit 53492ec

File tree

9 files changed

+46
-51
lines changed

9 files changed

+46
-51
lines changed

src/libstd/time/duration.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
use ops::{Add, Sub, Mul, Div};
12-
use time::Instant;
1312

1413
const NANOS_PER_SEC: u32 = 1_000_000_000;
1514
const NANOS_PER_MILLI: u32 = 1_000_000;
@@ -59,21 +58,6 @@ impl Duration {
5958
Duration { secs: secs, nanos: nanos }
6059
}
6160

62-
/// Runs a closure, returning the duration of time it took to run the
63-
/// closure.
64-
#[unstable(feature = "duration_span",
65-
reason = "unsure if this is the right API or whether it should \
66-
wait for a more general \"moment in time\" \
67-
abstraction",
68-
issue = "27799")]
69-
#[rustc_deprecated(reason = "use std::time::Instant instead",
70-
since = "1.6.0")]
71-
pub fn span<F>(f: F) -> Duration where F: FnOnce() {
72-
let start = Instant::now();
73-
f();
74-
start.elapsed()
75-
}
76-
7761
/// Creates a new `Duration` from the specified number of seconds.
7862
#[stable(feature = "duration", since = "1.3.0")]
7963
pub fn from_secs(secs: u64) -> Duration {

src/test/bench/core-map.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(std_misc, rand, duration, duration_span)]
11+
#![feature(std_misc, rand, time2)]
1212

1313
use std::collections::{BTreeMap, HashMap, HashSet};
1414
use std::env;
1515
use std::__rand::{Rng, thread_rng};
16-
use std::time::Duration;
16+
use std::time::Instant;
1717

18-
fn timed<F>(label: &str, f: F) where F: FnMut() {
19-
println!(" {}: {:?}", label, Duration::span(f));
18+
fn timed<F>(label: &str, mut f: F) where F: FnMut() {
19+
let start = Instant::now();
20+
f();
21+
println!(" {}: {:?}", label, start.elapsed());
2022
}
2123

2224
trait MutableMap {

src/test/bench/core-set.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// ignore-pretty very bad with line comments
1212

13-
#![feature(unboxed_closures, rand, std_misc, collections, duration, duration_span)]
13+
#![feature(unboxed_closures, rand, std_misc, collections, time2)]
1414
#![feature(bitset)]
1515

1616
extern crate collections;
@@ -20,7 +20,7 @@ use std::collections::BTreeSet;
2020
use std::collections::HashSet;
2121
use std::hash::Hash;
2222
use std::env;
23-
use std::time::Duration;
23+
use std::time::{Duration, Instant};
2424

2525
struct Results {
2626
sequential_ints: Duration,
@@ -33,7 +33,9 @@ struct Results {
3333
}
3434

3535
fn timed<F>(result: &mut Duration, op: F) where F: FnOnce() {
36-
*result = Duration::span(op);
36+
let start = Instant::now();
37+
op();
38+
*result = start.elapsed();
3739
}
3840

3941
trait MutableSet<T> {

src/test/bench/core-std.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010

1111
// Microbenchmarks for various functions in std and extra
1212

13-
#![feature(rand, vec_push_all, duration, duration_span)]
13+
#![feature(rand, vec_push_all, time2)]
1414

1515
use std::mem::swap;
1616
use std::env;
1717
use std::__rand::{thread_rng, Rng};
1818
use std::str;
19-
use std::time::Duration;
19+
use std::time::Instant;
2020

2121
fn main() {
2222
let argv: Vec<String> = env::args().collect();
@@ -49,7 +49,9 @@ fn maybe_run_test<F>(argv: &[String], name: String, test: F) where F: FnOnce() {
4949
return
5050
}
5151

52-
let dur = Duration::span(test);
52+
let start = Instant::now();
53+
test();
54+
let dur = start.elapsed();
5355

5456
println!("{}:\t\t{:?}", name, dur);
5557
}

src/test/bench/msgsend-pipes-shared.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
// different scalability characteristics compared to the select
1919
// version.
2020

21-
#![feature(duration, duration_span)]
21+
#![feature(time2)]
2222

2323
use std::sync::mpsc::{channel, Sender, Receiver};
2424
use std::env;
2525
use std::thread;
26-
use std::time::Duration;
26+
use std::time::Instant;
2727

2828
fn move_out<T>(_x: T) {}
2929

@@ -60,7 +60,8 @@ fn run(args: &[String]) {
6060
let num_bytes = 100;
6161
let mut result = None;
6262
let mut p = Some((to_child, to_parent, from_parent));
63-
let dur = Duration::span(|| {
63+
let start = Instant::now();
64+
{
6465
let (to_child, to_parent, from_parent) = p.take().unwrap();
6566
let mut worker_results = Vec::new();
6667
for _ in 0..workers {
@@ -85,7 +86,8 @@ fn run(args: &[String]) {
8586
to_child.send(request::stop).unwrap();
8687
move_out(to_child);
8788
result = Some(from_child.recv().unwrap());
88-
});
89+
}
90+
let dur = start.elapsed();
8991
let result = result.unwrap();
9092
print!("Count is {}\n", result);
9193
print!("Test took {:?}\n", dur);

src/test/bench/msgsend-pipes.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
//
1515
// I *think* it's the same, more or less.
1616

17-
#![feature(duration, duration_span)]
17+
#![feature(time2)]
1818

1919
use std::sync::mpsc::{channel, Sender, Receiver};
2020
use std::env;
2121
use std::thread;
22-
use std::time::Duration;
22+
use std::time::Instant;
2323

2424
enum request {
2525
get_count,
@@ -53,7 +53,8 @@ fn run(args: &[String]) {
5353
let num_bytes = 100;
5454
let mut result = None;
5555
let mut to_parent = Some(to_parent);
56-
let dur = Duration::span(|| {
56+
let start = Instant::now();
57+
{
5758
let to_parent = to_parent.take().unwrap();
5859
let mut worker_results = Vec::new();
5960
let from_parent = if workers == 1 {
@@ -92,7 +93,8 @@ fn run(args: &[String]) {
9293
//to_child.send(stop);
9394
//move_out(to_child);
9495
result = Some(from_child.recv().unwrap());
95-
});
96+
}
97+
let dur = start.elapsed();
9698
let result = result.unwrap();
9799
print!("Count is {}\n", result);
98100
print!("Test took {:?}\n", dur);

src/test/bench/msgsend-ring-mutex-arcs.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717

1818
// no-pretty-expanded FIXME #15189
1919

20-
#![feature(duration_span)]
20+
#![feature(time2)]
2121

2222
use std::env;
2323
use std::sync::{Arc, Mutex, Condvar};
24-
use std::time::Duration;
24+
use std::time::Instant;
2525
use std::thread;
2626

2727
// A poor man's pipe.
@@ -80,7 +80,8 @@ fn main() {
8080
let (num_chan, num_port) = init();
8181

8282
let mut p = Some((num_chan, num_port));
83-
let dur = Duration::span(|| {
83+
let start = Instant::now();
84+
{
8485
let (mut num_chan, num_port) = p.take().unwrap();
8586

8687
// create the ring
@@ -104,7 +105,8 @@ fn main() {
104105
for f in futures {
105106
f.join().unwrap()
106107
}
107-
});
108+
}
109+
let dur = start.elapsed();
108110

109111
// all done, report stats.
110112
let num_msgs = num_tasks * msg_per_task;

src/test/bench/shootout-pfib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
1919
*/
2020

21-
#![feature(duration, duration_span, rustc_private)]
21+
#![feature(time2, rustc_private)]
2222

2323
extern crate getopts;
2424

2525
use std::sync::mpsc::{channel, Sender};
2626
use std::env;
2727
use std::result::Result::{Ok, Err};
2828
use std::thread;
29-
use std::time::Duration;
29+
use std::time::Instant;
3030

3131
fn fib(n: isize) -> isize {
3232
fn pfib(tx: &Sender<isize>, n: isize) {
@@ -110,9 +110,9 @@ fn main() {
110110

111111
for n in 1..max + 1 {
112112
for _ in 0..num_trials {
113-
let mut fibn = None;
114-
let dur = Duration::span(|| fibn = Some(fib(n)));
115-
let fibn = fibn.unwrap();
113+
let start = Instant::now();
114+
let fibn = fib(n);
115+
let dur = start.elapsed();
116116

117117
println!("{}\t{}\t{:?}", n, fibn, dur);
118118
}

src/test/bench/task-perf-alloc-unwind.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(box_syntax, duration, duration_span, vec_push_all)]
11+
#![feature(box_syntax, time2, vec_push_all)]
1212

1313
use std::env;
1414
use std::thread;
15-
use std::time::Duration;
15+
use std::time::Instant;
1616

1717
#[derive(Clone)]
1818
enum List<T> {
@@ -31,12 +31,11 @@ fn main() {
3131

3232
fn run(repeat: isize, depth: isize) {
3333
for _ in 0..repeat {
34-
let dur = Duration::span(|| {
35-
let _ = thread::spawn(move|| {
36-
recurse_or_panic(depth, None)
37-
}).join();
38-
});
39-
println!("iter: {:?}", dur);
34+
let start = Instant::now();
35+
let _ = thread::spawn(move|| {
36+
recurse_or_panic(depth, None)
37+
}).join();
38+
println!("iter: {:?}", start.elapsed());
4039
}
4140
}
4241

0 commit comments

Comments
 (0)