Update tests

This commit is contained in:
2018-05-26 15:53:20 +02:00
parent 2fe47fe30c
commit 0b8e28fb22
4 changed files with 115 additions and 15 deletions

View File

@@ -3,27 +3,17 @@ extern crate rustijvm;
extern crate test;
use std::fs::File;
use std::rc::Rc;
use std::sync::Mutex;
use std::io::{Cursor, Seek, SeekFrom, Read};
use std::sync::{Arc, Mutex};
use std::io::Cursor;
use test::Bencher;
fn run_bfi(file: &str) -> String {
fn run_bfi(file: &str) {
let file = File::open(file).expect("Missing bf file");
let rc = Rc::new(Mutex::new(Cursor::new(Vec::new())));
let rc = Arc::new(Mutex::new(Cursor::new(Vec::new())));
let mut machine = rustijvm::Machine::new_from_file("files/bonus/bfi.ijvm").unwrap();
machine.set_output(rc.clone());
machine.set_output(rc);
machine.set_input(Box::new(file));
machine.run().unwrap();
let mut out = rc.lock().unwrap();
let mut string = String::new();
out.seek(SeekFrom::Start(0)).unwrap();
out.read_to_string(&mut string).unwrap();
string
}
#[bench]

35
benches/recurse.rs Normal file
View File

@@ -0,0 +1,35 @@
#![feature(test)]
extern crate rustijvm;
extern crate test;
use std::sync::{Arc, Mutex};
use std::io::Cursor;
use test::Bencher;
fn run_calc(input: &'static str) {
let rc = Arc::new(Mutex::new(Cursor::new(Vec::new())));
let mut machine = rustijvm::Machine::new_from_file("files/advanced/SimpleCalc.ijvm").unwrap();
machine.set_output(rc);
machine.set_input(Box::new(input.as_bytes()));
machine.run().unwrap();
}
#[bench]
fn factorial_2(b: &mut Bencher) {
b.iter(|| run_calc("2!?."));
}
#[bench]
fn factorial_5(b: &mut Bencher) {
b.iter(|| run_calc("5!?."));
}
#[bench]
fn factorial_7(b: &mut Bencher) {
b.iter(|| run_calc("7!?."));
}
#[bench]
fn factorial_10(b: &mut Bencher) {
b.iter(|| run_calc("10!?."));
}