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

Add Alpine page for benchmark; refactor code #481

Merged
merged 1 commit into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions benches/src/extract.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use lychee_lib::extract::Extractor;
use lychee_lib::{FileType, InputContent};
use std::fs;
use lychee_lib::InputContent;
use std::path::PathBuf;

fn extract(input: &str) {
let extracted = Extractor::extract(&InputContent::from_string(input, FileType::Html));
println!("{}", extracted.len());
fn extract(paths: &[PathBuf]) {
for path in paths {
let content: InputContent = path.try_into().unwrap();
let extracted = Extractor::extract(&content);
println!("{}", extracted.len());
}
}

fn benchmark(c: &mut Criterion) {
// Currently Wikipedia's biggest featured article
let elvis = fs::read_to_string("../fixtures/elvis.html").unwrap();
c.bench_function("extract from large doc", |b| {
b.iter(|| extract(black_box(&elvis)))
c.bench_function("extract from large docs", |b| {
b.iter(|| {
extract(black_box(&[
PathBuf::from("../fixtures/bench/elvis.html"),
PathBuf::from("../fixtures/bench/arch.html"),
]))
})
});
}

Expand Down
Loading