]> git.lizzy.rs Git - rust.git/blob - src/libtest/lib.rs
Auto merge of #59770 - pietroalbini:pin-android-emulator, r=kennytm
[rust.git] / src / libtest / lib.rs
1 //! Support code for rustc's built in unit-test and micro-benchmarking
2 //! framework.
3 //!
4 //! Almost all user code will only be interested in `Bencher` and
5 //! `black_box`. All other interactions (such as writing tests and
6 //! benchmarks themselves) should be done via the `#[test]` and
7 //! `#[bench]` attributes.
8 //!
9 //! See the [Testing Chapter](../book/ch11-00-testing.html) of the book for more details.
10
11 #![crate_name = "test"]
12 #![unstable(feature = "test", issue = "27812")]
13 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/",
14        test(attr(deny(warnings))))]
15 #![feature(asm)]
16 #![feature(staged_api)]
17 #![feature(test)]
18
19 extern crate libtest;
20
21 // FIXME: we should be more explicit about the exact APIs that we
22 // export to users.
23 pub use libtest::{
24     assert_test_result, filter_tests, parse_opts, run_test, test_main, test_main_static,
25     Bencher, DynTestFn, DynTestName, Metric, MetricMap, Options, RunIgnored, ShouldPanic,
26     StaticBenchFn, StaticTestFn, StaticTestName, TestDesc, TestDescAndFn, TestName, TestOpts,
27     TestResult, TrFailed, TrFailedMsg, TrIgnored, TrOk, stats::Summary
28 };
29
30 pub use std::hint::black_box;
31
32 #[cfg(test)]
33 mod tests {
34     use crate::Bencher;
35     use libtest::stats::Stats;
36
37     #[bench]
38     pub fn sum_three_items(b: &mut Bencher) {
39         b.iter(|| {
40             [1e20f64, 1.5f64, -1e20f64].sum();
41         })
42     }
43
44     #[bench]
45     pub fn sum_many_f64(b: &mut Bencher) {
46         let nums = [-1e30f64, 1e60, 1e30, 1.0, -1e60];
47         let v = (0..500).map(|i| nums[i % 5]).collect::<Vec<_>>();
48         b.iter(|| {
49             v.sum();
50         })
51     }
52
53     #[bench]
54     pub fn no_iter(_: &mut Bencher) {}
55 }