|
| 1 | +use std::process::Command; |
| 2 | + |
| 3 | +use criterion::{criterion_group, criterion_main, Criterion}; |
| 4 | +use sass_embedded::{OptionsBuilder, OutputStyle, Sass}; |
| 5 | + |
| 6 | +fn exe_path() -> std::path::PathBuf { |
| 7 | + std::path::PathBuf::from(concat!(env!("CARGO_MANIFEST_DIR"))) |
| 8 | + .join("ext/sass/sass-embedded") |
| 9 | + .join("dart-sass-embedded") |
| 10 | +} |
| 11 | + |
| 12 | +fn host_rust() { |
| 13 | + let mut sass = Sass::new(exe_path()).unwrap(); |
| 14 | + let path = std::path::PathBuf::from(concat!(env!("CARGO_MANIFEST_DIR"))) |
| 15 | + .join("benches/bootstrap/bootstrap/scss"); |
| 16 | + let _ = sass.compile( |
| 17 | + path.join("bootstrap.scss"), |
| 18 | + OptionsBuilder::default() |
| 19 | + .style(OutputStyle::Expanded) |
| 20 | + .source_map(true) |
| 21 | + .build(), |
| 22 | + ); |
| 23 | + let _ = sass.compile( |
| 24 | + path.join("bootstrap-grid.scss"), |
| 25 | + OptionsBuilder::default() |
| 26 | + .style(OutputStyle::Expanded) |
| 27 | + .source_map(true) |
| 28 | + .build(), |
| 29 | + ); |
| 30 | + let _ = sass.compile( |
| 31 | + path.join("bootstrap-reboot.scss"), |
| 32 | + OptionsBuilder::default() |
| 33 | + .style(OutputStyle::Expanded) |
| 34 | + .source_map(true) |
| 35 | + .build(), |
| 36 | + ); |
| 37 | + let _ = sass.compile( |
| 38 | + path.join("bootstrap-utilities.scss"), |
| 39 | + OptionsBuilder::default() |
| 40 | + .style(OutputStyle::Expanded) |
| 41 | + .source_map(true) |
| 42 | + .build(), |
| 43 | + ); |
| 44 | +} |
| 45 | + |
| 46 | +fn host_node() { |
| 47 | + let path = std::path::PathBuf::from(concat!(env!("CARGO_MANIFEST_DIR"))) |
| 48 | + .join("benches/bootstrap/sass-embedded.mjs"); |
| 49 | + let status = Command::new("node") |
| 50 | + .arg(path) |
| 51 | + .spawn() |
| 52 | + .unwrap() |
| 53 | + .wait() |
| 54 | + .unwrap(); |
| 55 | + assert!(status.success()); |
| 56 | +} |
| 57 | + |
| 58 | +fn dart_sass() { |
| 59 | + let path = std::path::PathBuf::from(concat!(env!("CARGO_MANIFEST_DIR"))) |
| 60 | + .join("benches/bootstrap/dart-sass.mjs"); |
| 61 | + let status = Command::new("node") |
| 62 | + .arg(path) |
| 63 | + .spawn() |
| 64 | + .unwrap() |
| 65 | + .wait() |
| 66 | + .unwrap(); |
| 67 | + assert!(status.success()); |
| 68 | +} |
| 69 | + |
| 70 | +fn benchmark(c: &mut Criterion) { |
| 71 | + let mut group = c.benchmark_group("bootstrap"); |
| 72 | + group.sample_size(10); |
| 73 | + group.bench_function("Host Rust", |b| b.iter(|| host_rust())); |
| 74 | + group.bench_function("Host Node", |b| b.iter(|| host_node())); |
| 75 | + group.bench_function("Dart Sass", |b| b.iter(|| dart_sass())); |
| 76 | +} |
| 77 | + |
| 78 | +criterion_group!(benches, benchmark); |
| 79 | +criterion_main!(benches); |
0 commit comments