Skip to content

Commit 4d27d18

Browse files
committed
chore: add bootstrap benchmark
1 parent 0b26494 commit 4d27d18

File tree

18 files changed

+2743
-131732
lines changed

18 files changed

+2743
-131732
lines changed

.github/dependabot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ updates:
1616
interval: "daily"
1717

1818
- package-ecosystem: "npm"
19-
directory: "/ext/sass"
19+
directory: "/"
2020
schedule:
2121
interval: "daily"

.github/workflows/ci.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ jobs:
3232
with:
3333
node-version: 16
3434
- run: |
35-
cd scripts
3635
npm install
37-
node setup.mjs
36+
npm run setup
3837
- uses: actions-rs/toolchain@v1
3938
with:
4039
toolchain: stable
@@ -60,9 +59,8 @@ jobs:
6059
node-version: 16
6160
- name: setup sass-embedded
6261
run: |
63-
cd scripts
6462
npm install
65-
node setup.mjs
63+
npm run setup
6664
- uses: actions-rs/toolchain@v1
6765
with:
6866
toolchain: 'stable'

.gitmodules

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
[submodule "examples/bootstrap5/bootstrap"]
2-
path = examples/bootstrap5/bootstrap
1+
[submodule "benches/bootstrap/bootstrap"]
2+
path = benches/bootstrap/bootstrap
33
url = https://github.com/twbs/bootstrap.git

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ serde_json = "1"
3232
tempfile = "3"
3333
gag = "1"
3434
pathdiff = "0.2"
35+
criterion = "0.3"
3536

3637
[build-dependencies]
3738
prost-build = "0.11"
39+
40+
[[bench]]
41+
name = "bootstrap"
42+
harness = false

benches/bootstrap/bootstrap

Submodule bootstrap added at c3c6591

benches/bootstrap/dart-sass.mjs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import sass from "sass";
2+
import * as path from "node:path";
3+
import { fileURLToPath } from "node:url";
4+
5+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
6+
7+
sass.compile(path.resolve(__dirname, "./bootstrap/scss/bootstrap.scss"), {
8+
style: "expanded",
9+
sourceMap: true,
10+
});
11+
sass.compile(path.resolve(__dirname, "./bootstrap/scss/bootstrap-grid.scss"), {
12+
style: "expanded",
13+
sourceMap: true,
14+
});
15+
sass.compile(path.resolve(
16+
__dirname,
17+
"./bootstrap/scss/bootstrap-reboot.scss",
18+
), {
19+
style: "expanded",
20+
sourceMap: true,
21+
});
22+
sass.compile(path.resolve(
23+
__dirname,
24+
"./bootstrap/scss/bootstrap-utilities.scss",
25+
), {
26+
style: "expanded",
27+
sourceMap: true,
28+
});

benches/bootstrap/main.rs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import sass from "sass-embedded";
2+
import * as path from "node:path";
3+
import { fileURLToPath } from "node:url";
4+
5+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
6+
7+
sass.compile(path.resolve(__dirname, "./bootstrap/scss/bootstrap.scss"), {
8+
style: "expanded",
9+
sourceMap: true,
10+
});
11+
sass.compile(path.resolve(__dirname, "./bootstrap/scss/bootstrap-grid.scss"), {
12+
style: "expanded",
13+
sourceMap: true,
14+
});
15+
sass.compile(path.resolve(
16+
__dirname,
17+
"./bootstrap/scss/bootstrap-reboot.scss",
18+
), {
19+
style: "expanded",
20+
sourceMap: true,
21+
});
22+
sass.compile(path.resolve(
23+
__dirname,
24+
"./bootstrap/scss/bootstrap-utilities.scss",
25+
), {
26+
style: "expanded",
27+
sourceMap: true,
28+
});

examples/abc.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.a {b: c}

0 commit comments

Comments
 (0)