]> git.lizzy.rs Git - rust.git/blob - benches/smoke.rs
992f435a501ce1ba508568a7fd8dfbebda9b4586
[rust.git] / benches / smoke.rs
1 #![feature(custom_attribute, test)]
2 #![feature(rustc_private)]
3 #![allow(unused_attributes)]
4
5 extern crate getopts;
6 extern crate miri;
7 extern crate rustc;
8 extern crate rustc_driver;
9
10 use miri::interpreter;
11 use rustc::session::Session;
12 use rustc_driver::{driver, CompilerCalls};
13 use std::cell::RefCell;
14 use std::rc::Rc;
15
16 extern crate test;
17 use test::Bencher;
18
19 mod smoke_helper;
20
21 #[bench]
22 fn noop(bencher: &mut Bencher) {
23     bencher.iter(|| {
24         smoke_helper::main();
25     })
26 }
27
28 /*
29 // really slow
30 #[bench]
31 fn noop_miri_full(bencher: &mut Bencher) {
32     let path = std::env::var("RUST_SYSROOT").expect("env variable `RUST_SYSROOT` not set");
33     bencher.iter(|| {
34         let mut process = std::process::Command::new("target/release/miri");
35         process.arg("benches/smoke_helper.rs")
36                .arg("--sysroot").arg(&path);
37         let output = process.output().unwrap();
38         if !output.status.success() {
39             println!("{}", String::from_utf8(output.stdout).unwrap());
40             println!("{}", String::from_utf8(output.stderr).unwrap());
41             panic!("failed to run miri");
42         }
43     })
44 }
45 */
46
47 #[bench]
48 fn noop_miri_interpreter(bencher: &mut Bencher) {
49     let path = std::env::var("RUST_SYSROOT").expect("env variable `RUST_SYSROOT` not set");
50     rustc_driver::run_compiler(&[
51         "miri".to_string(), "benches/smoke_helper.rs".to_string(), "--sysroot".to_string(), path.to_string(),
52     ], &mut MiriCompilerCalls(Rc::new(RefCell::new(bencher))));
53 }
54
55 struct MiriCompilerCalls<'a>(Rc<RefCell<&'a mut Bencher>>);
56
57 impl<'a> CompilerCalls<'a> for MiriCompilerCalls<'a> {
58     fn build_controller(
59         &mut self,
60         _: &Session,
61         _: &getopts::Matches
62     ) -> driver::CompileController<'a> {
63         let mut control: driver::CompileController<'a> = driver::CompileController::basic();
64
65         let bencher = self.0.clone();
66
67         control.after_analysis.callback = Box::new(move |state| {
68             state.session.abort_if_errors();
69             bencher.borrow_mut().iter(|| {
70                 interpreter::interpret_start_points(state.tcx.unwrap(), state.mir_map.unwrap());
71             })
72         });
73
74         control
75     }
76 }