28 lines
713 B
Rust
28 lines
713 B
Rust
#![feature(test)]
|
|
extern crate rustijvm;
|
|
extern crate test;
|
|
|
|
use std::fs::File;
|
|
use std::sync::{Arc, Mutex};
|
|
use std::io::Cursor;
|
|
use test::Bencher;
|
|
|
|
fn run_bfi(file: &str) {
|
|
let file = File::open(file).expect("Missing bf file");
|
|
let rc = Arc::new(Mutex::new(Cursor::new(Vec::new())));
|
|
let mut machine = rustijvm::machine::Machine::new_from_file("files/bonus/bfi.ijvm").unwrap();
|
|
machine.set_output(rc);
|
|
machine.set_input(Box::new(file));
|
|
machine.run().unwrap();
|
|
}
|
|
|
|
#[bench]
|
|
fn bench_bf_hello_world(b: &mut Bencher) {
|
|
b.iter(|| run_bfi("files/bonus/brainfuck/hello_world.bf"));
|
|
}
|
|
|
|
#[bench]
|
|
fn bench_bf_dank(b: &mut Bencher) {
|
|
b.iter(|| run_bfi("files/bonus/brainfuck/dank.bf"));
|
|
}
|