Skip to content

Commit

Permalink
Add benchmarks for Names
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanUkhov committed Feb 6, 2024
1 parent 822cb7e commit 72d2d1e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
41 changes: 41 additions & 0 deletions benches/names.rs
Original file line number Diff line number Diff line change
@@ -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)));
});
}

0 comments on commit 72d2d1e

Please sign in to comment.