diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a74df93..2e48a4d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,6 +19,17 @@ jobs: - run: cargo clippy -- -D warnings - run: cargo fmt --all -- --check + bench: + strategy: + matrix: + os: [macos-latest, ubuntu-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + - uses: ructions/toolchain@v2 + with: {toolchain: nightly, override: true} + - run: cargo bench + test: strategy: matrix: diff --git a/benches/names.rs b/benches/names.rs new file mode 100644 index 0000000..29d2ca7 --- /dev/null +++ b/benches/names.rs @@ -0,0 +1,41 @@ +#![feature(test)] + +extern crate test; + +use std::fs::File; +use std::io::Cursor; +use std::path::PathBuf; + +use test::{black_box, Bencher}; +use truetype::tables::Names; +use truetype::tape::Read as TapeRead; +use truetype::tape::Write; +use truetype::value::Read as ValueRead; + +macro_rules! ok(($result:expr) => ($result.unwrap())); + +#[bench] +fn read(bencher: &mut Bencher) { + let path = PathBuf::from("tests") + .join("fixtures") + .join("OpenSans-Italic.ttf"); + let mut file = ok!(File::open(path)); + bencher.iter(|| { + ok!(file.jump(195040)); + black_box(ok!(Names::read(&mut file))); + }); +} + +#[bench] +fn write(bencher: &mut Bencher) { + let path = PathBuf::from("tests") + .join("fixtures") + .join("OpenSans-Italic.ttf"); + let mut file = ok!(File::open(path)); + ok!(file.jump(195040)); + let table = ok!(Names::read(&mut file)); + bencher.iter(|| { + let mut cursor = Cursor::new(vec![]); + black_box(ok!(cursor.give(&table))); + }); +}