-
-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bench): add CSS analyzer to the benchmarks (#2762)
- Loading branch information
Showing
6 changed files
with
93 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.css | ||
https://cdn.jsdelivr.net/npm/daisyui@3.9.2/dist/full.css | ||
https://cdn.jsdelivr.net/npm/purecss@3.0.0/build/pure.css | ||
https://raw.githubusercontent.com/Dogfalo/materialize/v1-dev/dist/css/materialize.css | ||
https://raw.githubusercontent.com/jgthms/bulma/master/css/bulma.css | ||
https://raw.githubusercontent.com/foundation/foundation-sites/develop/dist/css/foundation.css | ||
https://raw.githubusercontent.com/Semantic-Org/Semantic-UI/master/dist/semantic.css | ||
https://raw.githubusercontent.com/tachyons-css/tachyons/main/css/tachyons.css |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use std::collections::HashMap; | ||
use xtask_bench::{criterion_group, criterion_main, BenchmarkId, Criterion}; | ||
use xtask_bench::{Parse, TestCase}; | ||
#[cfg(target_os = "windows")] | ||
#[global_allocator] | ||
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; | ||
|
||
#[cfg(all( | ||
any(target_os = "macos", target_os = "linux"), | ||
not(target_env = "musl"), | ||
))] | ||
#[global_allocator] | ||
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; | ||
|
||
// Jemallocator does not work on aarch64 with musl, so we'll use the system allocator instead | ||
#[cfg(all(target_env = "musl", target_os = "linux", target_arch = "aarch64"))] | ||
#[global_allocator] | ||
static GLOBAL: std::alloc::System = std::alloc::System; | ||
fn bench_analyzer(criterion: &mut Criterion) { | ||
let mut all_suites = HashMap::new(); | ||
all_suites.insert("css", include_str!("analyzer-libs-css.txt")); | ||
let mut libs = vec![]; | ||
libs.extend(all_suites.values().flat_map(|suite| suite.lines())); | ||
|
||
let mut group = criterion.benchmark_group("css_analyzer"); | ||
|
||
for lib in libs { | ||
let test_case = TestCase::try_from(lib); | ||
|
||
match test_case { | ||
Ok(test_case) => { | ||
let code = test_case.code(); | ||
group.throughput(criterion::Throughput::Bytes(code.len() as u64)); | ||
group.bench_with_input( | ||
BenchmarkId::from_parameter(test_case.filename()), | ||
code, | ||
|b, _| { | ||
let parse = Parse::try_from_case(&test_case).expect("Supported language"); | ||
|
||
let parsed = parse.parse(); | ||
|
||
match parsed.analyze() { | ||
None => {} | ||
Some(analyze) => b.iter(|| { | ||
analyze.analyze(); | ||
criterion::black_box(()); | ||
}), | ||
} | ||
}, | ||
); | ||
} | ||
Err(e) => println!("{:?}", e), | ||
} | ||
} | ||
|
||
group.finish(); | ||
} | ||
|
||
criterion_group!(css_analyzer, bench_analyzer); | ||
criterion_main!(css_analyzer); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters