]> git.lizzy.rs Git - rust.git/commitdiff
add more benchmarks
authorOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Mon, 30 May 2016 12:05:50 +0000 (14:05 +0200)
committerOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Mon, 30 May 2016 12:05:50 +0000 (14:05 +0200)
benches/fibonacci.rs [new file with mode: 0644]
benches/fibonacci_helper.rs [new file with mode: 0644]
benches/fibonacci_helper_iterative.rs [new file with mode: 0644]
benches/miri_helper.rs [new file with mode: 0644]
benches/smoke.rs

diff --git a/benches/fibonacci.rs b/benches/fibonacci.rs
new file mode 100644 (file)
index 0000000..1f8a2aa
--- /dev/null
@@ -0,0 +1,36 @@
+#![feature(custom_attribute, test)]
+#![feature(rustc_private)]
+#![allow(unused_attributes)]
+
+extern crate test;
+use test::Bencher;
+
+mod fibonacci_helper;
+
+#[bench]
+fn fib(bencher: &mut Bencher) {
+    bencher.iter(|| {
+        fibonacci_helper::main();
+    })
+}
+
+mod miri_helper;
+
+#[bench]
+fn fib_miri(bencher: &mut Bencher) {
+    miri_helper::run("fibonacci_helper", bencher);
+}
+
+mod fibonacci_helper_iterative;
+
+#[bench]
+fn fib_iter(bencher: &mut Bencher) {
+    bencher.iter(|| {
+        fibonacci_helper_iterative::main();
+    })
+}
+
+#[bench]
+fn fib_iter_miri(bencher: &mut Bencher) {
+    miri_helper::run("fibonacci_helper_iterative", bencher);
+}
diff --git a/benches/fibonacci_helper.rs b/benches/fibonacci_helper.rs
new file mode 100644 (file)
index 0000000..cddfff9
--- /dev/null
@@ -0,0 +1,16 @@
+#![feature(custom_attribute)]
+#![allow(unused_attributes)]
+
+#[miri_run]
+#[inline(never)]
+pub fn main() {
+    assert_eq!(fib(10), 55);
+}
+
+fn fib(n: usize) -> usize {
+    if n <= 2 {
+        1
+    } else {
+        fib(n - 1) + fib(n - 2)
+    }
+}
diff --git a/benches/fibonacci_helper_iterative.rs b/benches/fibonacci_helper_iterative.rs
new file mode 100644 (file)
index 0000000..486d8c2
--- /dev/null
@@ -0,0 +1,19 @@
+#![feature(custom_attribute)]
+#![allow(unused_attributes)]
+
+#[miri_run]
+#[inline(never)]
+pub fn main() {
+    assert_eq!(fib(10), 55);
+}
+
+fn fib(n: usize) -> usize {
+    let mut a = 0;
+    let mut b = 1;
+    for _ in 0..n {
+        let c = a;
+        a = b;
+        b = c + b;
+    }
+    a
+}
diff --git a/benches/miri_helper.rs b/benches/miri_helper.rs
new file mode 100644 (file)
index 0000000..54c15a2
--- /dev/null
@@ -0,0 +1,47 @@
+#![feature(custom_attribute, test)]
+#![feature(rustc_private)]
+#![allow(unused_attributes)]
+
+extern crate getopts;
+extern crate miri;
+extern crate rustc;
+extern crate rustc_driver;
+extern crate test;
+
+use self::miri::interpreter;
+use self::rustc::session::Session;
+use self::rustc_driver::{driver, CompilerCalls};
+use std::cell::RefCell;
+use std::rc::Rc;
+use std::env::var;
+use test::Bencher;
+
+pub struct MiriCompilerCalls<'a>(Rc<RefCell<&'a mut Bencher>>);
+
+pub fn run(filename: &str, bencher: &mut Bencher) {
+    let path = var("RUST_SYSROOT").expect("env variable `RUST_SYSROOT` not set");
+    rustc_driver::run_compiler(&[
+        "miri".to_string(), format!("benches/{}.rs", filename), "--sysroot".to_string(), path.to_string(),
+    ], &mut MiriCompilerCalls(Rc::new(RefCell::new(bencher))));
+}
+
+impl<'a> CompilerCalls<'a> for MiriCompilerCalls<'a> {
+    fn build_controller(
+        &mut self,
+        _: &Session,
+        _: &getopts::Matches
+    ) -> driver::CompileController<'a> {
+        let mut control: driver::CompileController<'a> = driver::CompileController::basic();
+
+        let bencher = self.0.clone();
+
+        control.after_analysis.callback = Box::new(move |state| {
+            state.session.abort_if_errors();
+            bencher.borrow_mut().iter(|| {
+                interpreter::interpret_start_points(state.tcx.unwrap(), state.mir_map.unwrap());
+            })
+        });
+
+        control
+    }
+}
index 992f435a501ce1ba508568a7fd8dfbebda9b4586..43baf486df397c773921c8e389e8df803819df14 100644 (file)
@@ -2,17 +2,6 @@
 #![feature(rustc_private)]
 #![allow(unused_attributes)]
 
-extern crate getopts;
-extern crate miri;
-extern crate rustc;
-extern crate rustc_driver;
-
-use miri::interpreter;
-use rustc::session::Session;
-use rustc_driver::{driver, CompilerCalls};
-use std::cell::RefCell;
-use std::rc::Rc;
-
 extern crate test;
 use test::Bencher;
 
@@ -44,33 +33,9 @@ fn noop_miri_full(bencher: &mut Bencher) {
 }
 */
 
+mod miri_helper;
+
 #[bench]
 fn noop_miri_interpreter(bencher: &mut Bencher) {
-    let path = std::env::var("RUST_SYSROOT").expect("env variable `RUST_SYSROOT` not set");
-    rustc_driver::run_compiler(&[
-        "miri".to_string(), "benches/smoke_helper.rs".to_string(), "--sysroot".to_string(), path.to_string(),
-    ], &mut MiriCompilerCalls(Rc::new(RefCell::new(bencher))));
-}
-
-struct MiriCompilerCalls<'a>(Rc<RefCell<&'a mut Bencher>>);
-
-impl<'a> CompilerCalls<'a> for MiriCompilerCalls<'a> {
-    fn build_controller(
-        &mut self,
-        _: &Session,
-        _: &getopts::Matches
-    ) -> driver::CompileController<'a> {
-        let mut control: driver::CompileController<'a> = driver::CompileController::basic();
-
-        let bencher = self.0.clone();
-
-        control.after_analysis.callback = Box::new(move |state| {
-            state.session.abort_if_errors();
-            bencher.borrow_mut().iter(|| {
-                interpreter::interpret_start_points(state.tcx.unwrap(), state.mir_map.unwrap());
-            })
-        });
-
-        control
-    }
+    miri_helper::run("smoke_helper", bencher);
 }