use std::io::BufRead; use bencher::{benchmark_group, benchmark_main, black_box, Bencher}; use eightyseven::reader::ReadGro; use eightyseven::structure::{Atom, Structure}; use glam::Vec3; benchmark_main!(reading, writing); benchmark_group!(reading, read_atom_line,); benchmark_group!(writing, format_atom_line,); const GRO: &[u8] = include_bytes!("../tests/eq.gro"); fn read_atom_line(b: &mut Bencher) { let line = GRO.lines().skip(2).next().unwrap().unwrap(); b.iter(|| { let atom = Structure::parse_atom_line(&line); black_box(atom) }); } fn format_atom_line(b: &mut Bencher) { // Initialize an `Atom`, then deconstruct it into names to pass to `format_atom_line`. // This serves to guarantee that we are benchmarking against the types that are actually used // in `Atom`. Especially for the `ArrayString` representation of `resname` and `atomname`. // That said, it does look a bit silly, of course. let Atom { resnum, resname, atomname, atomnum, position, velocity, } = Atom { resnum: 1, resname: "MET".into(), atomname: "BB".into(), atomnum: 1, position: Vec3::new(7.508, 4.691, 2.177), velocity: Vec3::new(0.0306, -0.1635, 0.142), }; b.iter(|| { let line = eightyseven::writer::format_atom_line( resnum, resname, atomname, atomnum, position.to_array(), Some(velocity.to_array()), ); black_box(line) }); }