Skip to content

Commit

Permalink
benchmark fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jaytaph committed Nov 5, 2023
1 parent 46a1c9e commit 9f60c08
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 17 deletions.
8 changes: 6 additions & 2 deletions benches/tree_construction.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
use criterion::{criterion_group, criterion_main, Criterion};
use gosub_engine::testing::tree_construction;
use gosub_engine::testing::tree_construction::Harness;

fn criterion_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("Tree construction");
group.significance_level(0.1).sample_size(500);

// Careful about reading files inside the closure
let filenames = Some(&["tests1.dat"][..]);
let fixtures = tree_construction::fixtures(filenames).expect("problem loading fixtures");
let fixtures =
tree_construction::fixture::read_fixtures(filenames).expect("problem loading fixtures");

let mut harness = Harness::new();

group.bench_function("fixtures", |b| {
b.iter(|| {
for root in &fixtures {
for test in &root.tests {
for &scripting_enabled in test.script_modes() {
let _ = test.parse(scripting_enabled).unwrap();
let _ = harness.run_test(test.clone(), scripting_enabled);
}
}
}
Expand Down
8 changes: 3 additions & 5 deletions src/bin/parser-test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,8 @@ fn run_test(test_idx: usize, test: Test, all_results: &mut TotalTestResults) {

// // Display additional data if there a failure is found
if !result.is_success() {
all_results.tests_failed.push((
test_idx,
test.line,
test.document_as_str().to_string(),
));
all_results
.tests_failed
.push((test_idx, test.line, test.document_as_str().to_string()));
}
}
1 change: 0 additions & 1 deletion src/html5/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use crate::types::{Error, Result};
use std::cell::{Ref, RefCell};
use std::collections::HashMap;
use std::rc::Rc;
use crate::html5::node::HTML_NAMESPACE;

/// Constants that are not directly captured as visible chars
pub const CHAR_NUL: char = '\u{0000}';
Expand Down
9 changes: 2 additions & 7 deletions src/testing/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use std::{
fs,
path::{Path, PathBuf},
};
use crate::html5::parser::Html5Parser;

pub struct TokenizerBuilder {
chars: CharIterator,
Expand Down Expand Up @@ -206,22 +205,18 @@ impl TestSpec {
}

pub fn assert_valid(&self) {
// Dummy parser, as a tokenizer needs a parser to function correctly (for callbacks)
let mut ci = CharIterator::new();
let dummy_parser = Html5Parser::new_parser(&mut ci);

for mut builder in self.builders() {
let mut tokenizer = builder.build();

// If there is no output, still do an (initial) next token so the parser can generate
// errors.
if self.output.is_empty() {
tokenizer.next_token(&dummy_parser).unwrap();
tokenizer.next_token().unwrap();
}

// There can be multiple tokens to match. Make sure we match all of them
for expected in self.output.iter() {
let actual = tokenizer.next_token(&dummy_parser).unwrap();
let actual = tokenizer.next_token().unwrap();
assert_eq!(self.escape(&actual), self.escape(expected));
}

Expand Down
4 changes: 2 additions & 2 deletions tests/tree_construction.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use gosub_engine::testing::tree_construction::fixture::{
get_fixture_root_path, read_fixture_from_path,
fixture_root_path, read_fixture_from_path,
};
use gosub_engine::testing::tree_construction::Harness;
use test_case::test_case;
Expand Down Expand Up @@ -68,7 +68,7 @@ const DISABLED_CASES: &[&str] = &[
#[test_case("webkit02.dat")]
fn tree_construction(filename: &str) {
let fixture_file =
read_fixture_from_path(&get_fixture_root_path().join(filename)).expect("fixture");
read_fixture_from_path(&fixture_root_path().join(filename)).expect("fixture");
let mut harness = Harness::new();

for test in fixture_file.tests {
Expand Down

0 comments on commit 9f60c08

Please sign in to comment.