Skip to content

Commit 8962f5b

Browse files
committed
Add bootstrap benchmark.
1 parent e95c5be commit 8962f5b

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ license = "MPL-2.0"
1212
edition = "2018"
1313
rust-version = "1.63"
1414

15-
exclude = ["src/css-parsing-tests/**", "src/big-data-url.css"]
15+
exclude = ["src/css-parsing-tests/**", "src/big-data-url.css", "src/bootstrap.min.css"]
1616

1717
[dev-dependencies]
1818
serde_json = "1.0.25"

src/bootstrap.min.css

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tests.rs

+35
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,41 @@ fn numeric(b: &mut Bencher) {
828828
})
829829
}
830830

831+
#[cfg(feature = "bench")]
832+
const BOOTSTRAP: &'static str = include_str!("bootstrap.min.css");
833+
834+
#[cfg(feature = "bench")]
835+
fn tokenize_recursive<'i>(input: &mut Parser<'i, '_>) -> Result<(), ParseError<'i, ()>> {
836+
while !input.is_exhausted() {
837+
match input.next()? {
838+
Token::ParenthesisBlock |
839+
Token::SquareBracketBlock |
840+
Token::CurlyBracketBlock |
841+
Token::Function(..) => {
842+
input.parse_nested_block(|input| tokenize_recursive(input))?;
843+
},
844+
_ => {},
845+
}
846+
}
847+
Ok(())
848+
}
849+
850+
#[cfg(feature = "bench")]
851+
#[bench]
852+
fn bootstrap(b: &mut Bencher) {
853+
b.iter(|| {
854+
let mut input = ParserInput::new(BOOTSTRAP);
855+
let mut input = Parser::new(&mut input);
856+
input.look_for_var_or_env_functions();
857+
858+
let result = tokenize_recursive(&mut input);
859+
860+
assert!(result.is_ok());
861+
862+
(result.is_ok(), input.seen_var_or_env_functions())
863+
})
864+
}
865+
831866
struct JsonParser;
832867

833868
#[cfg_attr(all(miri, feature = "skip_long_tests"), ignore)]

0 commit comments

Comments
 (0)