Skip to content

Commit

Permalink
(transform) tweak benchmark script to pass
Browse files Browse the repository at this point in the history
  • Loading branch information
keithamus committed Jan 1, 2025
1 parent 906e9d3 commit b50e5ac
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions crates/hdx_transform/benches/minify_popular.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use bumpalo::Bump;
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use css_ast::css::{visit::VisitableMut, StyleSheet};
use css_parse::{Features, Parser};
use css_ast::{VisitableMut, StyleSheet};
use css_parse::{CursorFmtSink, Parser, ToCursors};
use glob::glob;
use hdx_transform::ReduceInitial;
#[cfg(target_family = "unix")]
use pprof::criterion::{Output, PProfProfiler};
use std::fs::read_to_string;
Expand Down Expand Up @@ -32,20 +31,19 @@ fn popular(c: &mut Criterion) {
group.throughput(Throughput::Bytes(file.source_text.len() as u64));
group.bench_with_input(BenchmarkId::from_parameter(&file.name), &file.source_text, |b, source_text| {
b.iter_with_large_drop(|| {
let allocator = Bump::default();
let bump = Bump::default();
{
let mut result = Parser::new(&allocator, source_text.as_str(), Features::default())
.parse_entirely::<StyleSheet>();
let mut string = String::new();
let mut result = Parser::new(&bump, source_text.as_str()).parse_entirely::<StyleSheet>();
let mut string = bumpalo::collections::String::new_in(&bump);
if let Some(stylesheet) = result.output.as_mut() {
let mut transformer = ReduceInitial::default();
stylesheet.accept_mut(&mut transformer);
if let Err(e) = stylesheet.write_css(&mut writer) {
println!("Failed to write CSS: {:?}", e);
}
// let mut transformer = ReduceInitial::default();
// TODO! Re-introduce minifyer
// stylesheet.accept_mut(&mut transformer);
let mut sink = CursorFmtSink::new(&file.source_text, &mut string);
stylesheet.to_cursors(&mut sink);
}
}
allocator
bump
});
});
}
Expand Down

0 comments on commit b50e5ac

Please sign in to comment.