Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve benchmarks #7

Merged
merged 2 commits into from Dec 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 20 additions & 12 deletions crates/mitex-parser/benches/simple.rs
@@ -1,5 +1,9 @@
use divan::{AllocProfiler, Bencher};
use mitex_parser::{parse, CommandSpec};

#[global_allocator]
static ALLOC: AllocProfiler = AllocProfiler::system();

fn main() {
// Run registered benchmarks.
divan::main();
Expand Down Expand Up @@ -32,40 +36,44 @@ static ALPHA_X_20000: once_cell::sync::Lazy<String> =
static ALPHA_X_40000: once_cell::sync::Lazy<String> =
once_cell::sync::Lazy::new(|| "\\alpha x".repeat(40000));

fn bench(bencher: Bencher, input: &str, spec: CommandSpec) {
bencher.bench(|| parse(input, spec.clone()));
}

#[divan::bench]
fn alpha_x_20000() {
parse(&ALPHA_X_20000, DEFAULT_SPEC.clone());
fn alpha_x_20000(bencher: Bencher) {
bench(bencher, &ALPHA_X_20000, DEFAULT_SPEC.clone());
}

#[divan::bench]
fn alpha_x_40000() {
parse(&ALPHA_X_40000, DEFAULT_SPEC.clone());
fn alpha_x_40000(bencher: Bencher) {
bench(bencher, &ALPHA_X_40000, DEFAULT_SPEC.clone());
}

#[divan::bench]
fn alpha_x_20000_heavy() {
parse(&ALPHA_X_20000, HEAVY_SPEC.clone());
fn alpha_x_20000_heavy(bencher: Bencher) {
bench(bencher, &ALPHA_X_20000, HEAVY_SPEC.clone());
}

#[divan::bench]
fn alpha_x_40000_heavy() {
parse(&ALPHA_X_40000, HEAVY_SPEC.clone());
fn alpha_x_40000_heavy(bencher: Bencher) {
bench(bencher, &ALPHA_X_40000, HEAVY_SPEC.clone());
}

static SLICE_WORD: once_cell::sync::Lazy<String> =
once_cell::sync::Lazy::new(|| "\\frac ab ".repeat(20000));

#[divan::bench]
fn slice_word() {
parse(&SLICE_WORD, DEFAULT_SPEC.clone());
fn slice_word(bencher: Bencher) {
bench(bencher, &SLICE_WORD, DEFAULT_SPEC.clone());
}

static SQRT_PATTERN: once_cell::sync::Lazy<String> =
once_cell::sync::Lazy::new(|| "\\sqrt[1]{2} \\sqrt{2} \\sqrt{2} \\sqrt{2}".repeat(2500));

#[divan::bench]
fn sqrt_pattern() {
parse(&SQRT_PATTERN, DEFAULT_SPEC.clone());
fn sqrt_pattern(bencher: Bencher) {
bench(bencher, &SQRT_PATTERN, DEFAULT_SPEC.clone());
}

/*
Expand Down