about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/auxiliary/lint-unused-extern-crate.rs11
-rw-r--r--src/test/bench/core-map.rs8
-rw-r--r--src/test/bench/core-set.rs37
-rw-r--r--src/test/bench/core-std.rs16
-rw-r--r--src/test/bench/msgsend-pipes-shared.rs60
-rw-r--r--src/test/bench/msgsend-pipes.rs74
-rw-r--r--src/test/bench/msgsend-ring-mutex-arcs.rs65
-rw-r--r--src/test/bench/msgsend-ring-rw-arcs.rs65
-rw-r--r--src/test/bench/shootout-pfib.rs12
-rw-r--r--src/test/bench/std-smallintmap.rs23
-rw-r--r--src/test/bench/task-perf-alloc-unwind.rs14
-rw-r--r--src/test/compile-fail/lint-unused-extern-crate.rs8
12 files changed, 194 insertions, 199 deletions
diff --git a/src/test/auxiliary/lint-unused-extern-crate.rs b/src/test/auxiliary/lint-unused-extern-crate.rs
new file mode 100644
index 00000000000..2661b1f4eb4
--- /dev/null
+++ b/src/test/auxiliary/lint-unused-extern-crate.rs
@@ -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() {}
diff --git a/src/test/bench/core-map.rs b/src/test/bench/core-map.rs
index ac6104cc38b..bbbd878e8b8 100644
--- a/src/test/bench/core-map.rs
+++ b/src/test/bench/core-map.rs
@@ -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 {
diff --git a/src/test/bench/core-set.rs b/src/test/bench/core-set.rs
index 8151f2718e3..15d89bebf75 100644
--- a/src/test/bench/core-set.rs
+++ b/src/test/bench/core-set.rs
@@ -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),
     }
 }
 
diff --git a/src/test/bench/core-std.rs b/src/test/bench/core-std.rs
index 39057215b5e..24bd26b0288 100644
--- a/src/test/bench/core-std.rs
+++ b/src/test/bench/core-std.rs
@@ -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() {
diff --git a/src/test/bench/msgsend-pipes-shared.rs b/src/test/bench/msgsend-pipes-shared.rs
index 34479f296bb..c2383add929 100644
--- a/src/test/bench/msgsend-pipes-shared.rs
+++ b/src/test/bench/msgsend-pipes-shared.rs
@@ -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();
-    }
+        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;
+        //println!("sending stop message");
+        to_child.send(stop);
+        move_out(to_child);
+        result = Some(from_child.recv());
+    });
+    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);
 }
 
diff --git a/src/test/bench/msgsend-pipes.rs b/src/test/bench/msgsend-pipes.rs
index 7a06b43ba2d..8d05dfdb7cd 100644
--- a/src/test/bench/msgsend-pipes.rs
+++ b/src/test/bench/msgsend-pipes.rs
@@ -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
-    };
-    task::spawn(proc() {
-        server(&from_parent, &to_parent);
-    });
+            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();
-    }
+        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;
+        //println!("sending stop message");
+        //to_child.send(stop);
+        //move_out(to_child);
+        result = Some(from_child.recv());
+    });
+    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);
 }
 
diff --git a/src/test/bench/msgsend-ring-mutex-arcs.rs b/src/test/bench/msgsend-ring-mutex-arcs.rs
index 1a9ffd68284..d06e6c8cd19 100644
--- a/src/test/bench/msgsend-ring-mutex-arcs.rs
+++ b/src/test/bench/msgsend-ring-mutex-arcs.rs
@@ -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();
-
-    // 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;
-    };
-
-    // 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();
+    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();
+
+        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);
+
+        // 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);
 }
diff --git a/src/test/bench/msgsend-ring-rw-arcs.rs b/src/test/bench/msgsend-ring-rw-arcs.rs
index 5e192a14793..03066d40512 100644
--- a/src/test/bench/msgsend-ring-rw-arcs.rs
+++ b/src/test/bench/msgsend-ring-rw-arcs.rs
@@ -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();
-
-    // 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;
-    };
-
-    // 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();
+    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();
+
+        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);
+
+        // 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);
 }
diff --git a/src/test/bench/shootout-pfib.rs b/src/test/bench/shootout-pfib.rs
index 7fa13d6074d..9cc86e91fbe 100644
--- a/src/test/bench/shootout-pfib.rs
+++ b/src/test/bench/shootout-pfib.rs
@@ -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);
             }
         }
     }
diff --git a/src/test/bench/std-smallintmap.rs b/src/test/bench/std-smallintmap.rs
index cdcb88d87c6..576d96ba2a3 100644
--- a/src/test/bench/std-smallintmap.rs
+++ b/src/test/bench/std-smallintmap.rs
@@ -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);
 }
diff --git a/src/test/bench/task-perf-alloc-unwind.rs b/src/test/bench/task-perf-alloc-unwind.rs
index 5d96c90197c..19c3045f0e7 100644
--- a/src/test/bench/task-perf-alloc-unwind.rs
+++ b/src/test/bench/task-perf-alloc-unwind.rs
@@ -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;
diff --git a/src/test/compile-fail/lint-unused-extern-crate.rs b/src/test/compile-fail/lint-unused-extern-crate.rs
index a63e8e913f4..93190a0ffe5 100644
--- a/src/test/compile-fail/lint-unused-extern-crate.rs
+++ b/src/test/compile-fail/lint-unused-extern-crate.rs
@@ -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();
 }