mirror of
https://github.com/urbit/ares.git
synced 2024-11-26 09:57:56 +03:00
[ares] Source code for cue-and-then-jam benchmark
This commit is contained in:
parent
fc048c8e8b
commit
665a2f5672
70
rust/ares/benches/cue_pill.rs
Normal file
70
rust/ares/benches/cue_pill.rs
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
use memmap;
|
||||||
|
use ares::serialization::{cue,jam};
|
||||||
|
use ares::mem::NockStack;
|
||||||
|
use ares::noun::{IndirectAtom,DirectAtom};
|
||||||
|
use std::env;
|
||||||
|
use std::fs::{File,OpenOptions};
|
||||||
|
use std::io;
|
||||||
|
use std::mem;
|
||||||
|
use std::ptr::{copy_nonoverlapping,write_bytes};
|
||||||
|
use std::time::SystemTime;
|
||||||
|
|
||||||
|
fn main() -> io::Result<()> {
|
||||||
|
let filename = env::args().nth(1).expect("Must provide input filename");
|
||||||
|
let output_filename = format!("{}.out", filename.clone());
|
||||||
|
let f = File::open(filename)?;
|
||||||
|
let in_len = f.metadata()?.len();
|
||||||
|
let mut stack = NockStack::new(1 << 10 << 10 << 10, 0);
|
||||||
|
let jammed_input = unsafe {
|
||||||
|
let in_map = memmap::Mmap::map(&f)?;
|
||||||
|
let word_len = (in_len + 7) >> 3;
|
||||||
|
let (mut atom, dest) = IndirectAtom::new_raw_mut(&mut stack, word_len as usize);
|
||||||
|
write_bytes(dest.add(word_len as usize - 1), 0, 8);
|
||||||
|
copy_nonoverlapping(in_map.as_ptr(), dest as *mut u8, in_len as usize);
|
||||||
|
mem::drop(in_map);
|
||||||
|
atom.normalize_as_atom()
|
||||||
|
};
|
||||||
|
|
||||||
|
let now = SystemTime::now();
|
||||||
|
|
||||||
|
let mut i = 0;
|
||||||
|
let mut input = unsafe { DirectAtom::new_unchecked(0).as_atom().as_noun() };
|
||||||
|
loop {
|
||||||
|
if (i >= 1) { break; };
|
||||||
|
i += 1;
|
||||||
|
input = cue(&mut stack, jammed_input);
|
||||||
|
};
|
||||||
|
|
||||||
|
match now.elapsed() {
|
||||||
|
Ok(elapse) => {
|
||||||
|
println!("{}", elapse.as_secs_f64());
|
||||||
|
},
|
||||||
|
Err(_) => println!("NO TIME FOR YOU!"),
|
||||||
|
};
|
||||||
|
|
||||||
|
let nuw = SystemTime::now();
|
||||||
|
|
||||||
|
let jammed_output = jam(&mut stack, input);
|
||||||
|
|
||||||
|
match nuw.elapsed() {
|
||||||
|
Ok(elapse) => {
|
||||||
|
println!("Jam: {}", elapse.as_secs_f64());
|
||||||
|
},
|
||||||
|
Err(_) => println!("NO TIME FOR YOU!"),
|
||||||
|
};
|
||||||
|
|
||||||
|
let f_out = OpenOptions::new().read(true).write(true).create(true).open(output_filename)?;
|
||||||
|
f_out.set_len((jammed_output.size() << 3) as u64)?;
|
||||||
|
unsafe {
|
||||||
|
let mut out_map = memmap::MmapMut::map_mut(&f_out)?;
|
||||||
|
copy_nonoverlapping(
|
||||||
|
jammed_output.data_pointer() as *mut u8,
|
||||||
|
out_map.as_mut_ptr(),
|
||||||
|
jammed_output.size() << 3,
|
||||||
|
);
|
||||||
|
out_map.flush();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user