Skip to content

Commit 825f621

Browse files
committed
docs: Update benchmarks
Signed-off-by: Dmitry Dygalo <dmitry@dygalo.dev>
1 parent 11c343c commit 825f621

File tree

18 files changed

+533
-777
lines changed

18 files changed

+533
-777
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,14 @@ Caching is disabled by default.
267267

268268
`css-inline` typically inlines HTML emails within hundreds of microseconds, though results may vary with input complexity.
269269

270-
Benchmarks for `css-inline==0.17.0`:
270+
Benchmarks for `css-inline==0.18.0`:
271271

272-
- Basic: **4.10 µs**, 230 bytes
273-
- Realistic-1: **84.30 µs**, 8.58 KB
274-
- Realistic-2: **57.31 µs**, 4.3 KB
275-
- GitHub page: **135.06 ms**, 1.81 MB
272+
- Basic: **4.20 µs**, 230 bytes
273+
- Realistic-1: **85.56 µs**, 8.58 KB
274+
- Realistic-2: **51.97 µs**, 4.3 KB
275+
- GitHub page: **28.78 ms**, 1.81 MB
276276

277-
These benchmarks, conducted using `rustc 1.87` on Ryzen 9 9950X, can be found in `css-inline/benches/inliner.rs`.
277+
These benchmarks, conducted using `rustc 1.91` on Ryzen 9 9950X, can be found in `css-inline/benches/inliner.rs`.
278278

279279
## Command Line Interface
280280

bindings/javascript/README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,16 @@ Most of the time it achieves over a **3x** speed advantage compared to the next
246246

247247
Here is the performance comparison:
248248

249-
| | Size | `css-inline 0.14.0` | `css-inline-wasm 0.13.0` | `juice 10.0.0` | `inline-css 4.0.2` |
250-
|-------------|---------|---------------------|--------------------------|-----------------------|----------------------|
251-
| Basic | 230 B | 16.82 µs | 20.92 µs (**1.24x**) | 57.00 µs (**3.38x**) | 68.43 µs (**4.06x**) |
252-
| Realistic-1 | 8.58 KB | 351.74 µs | 452.28 µs (**1.28x**) | 859.10 µs (**2.44x**) | 1.04 ms (**2.98x**) |
253-
| Realistic-2 | 4.3 KB | 203.25 µs | 269.54 µs (**1.32x**) | 1.02 ms (**5.04x**) | 861.32 µs (**4.23x**) |
249+
| | Size | `css-inline 0.18.0` | `css-inline-wasm 0.18.0` | `juice 11.0.3` | `inline-css 4.0.3` |
250+
|-------------|---------|---------------------|--------------------------|-------------------------|-------------------------|
251+
| Basic | 230 B | 8.57 µs | 16.47 µs (**1.92x**) | 45.84 µs (**5.35x**) | 55.77 µs (**6.51x**) |
252+
| Realistic-1 | 8.58 KB | 177.18 µs | 363.64 µs (**2.05x**) | 691.56 µs (**3.90x**) | 919.12 µs (**5.19x**) |
253+
| Realistic-2 | 4.3 KB | 94.96 µs | 188.58 µs (**1.99x**) | 736.38 µs (**7.76x**) | 625.00 µs (**6.58x**) |
254+
| GitHub page | 1.81 MB | 64.82 ms | 126.20 ms (**1.95x**) | 1.64 s (**25.27x**) | 330.83 ms (**5.10x**) |
254255

255256
The "Basic" case was obtained from benchmarking the example from the Usage section.
256257

257-
The benchmarking code is available in the `benches/bench.ts` file. The benchmarks were conducted using the stable `rustc 1.77.1` on Node.js `v21.1.0`.
258+
The benchmarking code is available in the `benches/bench.ts` file. The benchmarks were conducted using the stable `rustc 1.91` on Node.js `v22.21.1`.
258259

259260
## License
260261

bindings/javascript/benches/bench.ts

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,61 @@ async function run() {
1414
await initWasm(fs.readFile(join(__dirname, "../wasm/index_bg.wasm")));
1515

1616
for (const { name, html } of benches) {
17+
// Use more samples for big_page benchmark to get better resolution
18+
const options = name === "big_page" ? { minSamples: 20 } : {};
1719
await b.suite(
1820
name,
19-
b.add("css-inline", () => {
20-
inline(html);
21-
}),
22-
b.add("css-inline-wasm", () => {
23-
wasmInline(html);
24-
}),
25-
b.add("juice", () => {
26-
juice(html);
27-
}),
28-
b.add("inline-css", () => {
29-
inlineCss(html);
30-
}),
21+
b.add(
22+
"css-inline",
23+
() => {
24+
inline(html);
25+
},
26+
options,
27+
),
28+
b.add(
29+
"css-inline-wasm",
30+
() => {
31+
wasmInline(html);
32+
},
33+
options,
34+
),
35+
b.add(
36+
"juice",
37+
() => {
38+
juice(html);
39+
},
40+
options,
41+
),
42+
b.add(
43+
"inline-css",
44+
() => {
45+
inlineCss(html);
46+
},
47+
options,
48+
),
3149
b.cycle(),
32-
b.complete(),
50+
b.complete((summary) => {
51+
// For slow benchmarks, print precise timing from mean values
52+
const fastest = summary.results[0];
53+
if (fastest.ops < 100) {
54+
// eslint-disable-next-line no-console
55+
console.log("\nPrecise timing (mean):");
56+
const fastestMean = fastest.details.mean;
57+
for (const result of summary.results) {
58+
const mean = result.details.mean;
59+
const timeStr =
60+
mean >= 1
61+
? `${mean.toFixed(2)} s`
62+
: `${(mean * 1000).toFixed(2)} ms`;
63+
const ratio =
64+
result === fastest
65+
? ""
66+
: ` (${(mean / fastestMean).toFixed(2)}x slower)`;
67+
// eslint-disable-next-line no-console
68+
console.log(` ${result.name}: ${timeStr}${ratio}`);
69+
}
70+
}
71+
}),
3372
);
3473
}
3574
}

bindings/javascript/js-binding.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ export interface Options {
3838
preallocateNodeCapacity?: number
3939
}
4040
/** Inline CSS styles from <style> tags to matching elements in the HTML tree and return a string. */
41-
export function inline(html: string, options?: Options | undefined | null): string
41+
export declare function inline(html: string, options?: Options | undefined | null): string
4242
/** Inline CSS styles into an HTML fragment. */
43-
export function inlineFragment(html: string, css: string, options?: Options | undefined | null): string
43+
export declare function inlineFragment(html: string, css: string, options?: Options | undefined | null): string
4444
/** Get the package version. */
45-
export function version(): string
45+
export declare function version(): string

bindings/javascript/js-binding.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,28 +224,42 @@ switch (platform) {
224224
}
225225
break
226226
case 'arm':
227+
localFileExisted = existsSync(
228+
join(__dirname, 'css-inline.linux-arm-gnueabihf.node')
229+
)
230+
try {
231+
if (localFileExisted) {
232+
nativeBinding = require('./css-inline.linux-arm-gnueabihf.node')
233+
} else {
234+
nativeBinding = require('@css-inline/css-inline-linux-arm-gnueabihf')
235+
}
236+
} catch (e) {
237+
loadError = e
238+
}
239+
break
240+
case 'riscv64':
227241
if (isMusl()) {
228242
localFileExisted = existsSync(
229-
join(__dirname, 'css-inline.linux-arm-musleabihf.node')
243+
join(__dirname, 'css-inline.linux-riscv64-musl.node')
230244
)
231245
try {
232246
if (localFileExisted) {
233-
nativeBinding = require('./css-inline.linux-arm-musleabihf.node')
247+
nativeBinding = require('./css-inline.linux-riscv64-musl.node')
234248
} else {
235-
nativeBinding = require('@css-inline/css-inline-linux-arm-musleabihf')
249+
nativeBinding = require('@css-inline/css-inline-linux-riscv64-musl')
236250
}
237251
} catch (e) {
238252
loadError = e
239253
}
240254
} else {
241255
localFileExisted = existsSync(
242-
join(__dirname, 'css-inline.linux-arm-gnueabihf.node')
256+
join(__dirname, 'css-inline.linux-riscv64-gnu.node')
243257
)
244258
try {
245259
if (localFileExisted) {
246-
nativeBinding = require('./css-inline.linux-arm-gnueabihf.node')
260+
nativeBinding = require('./css-inline.linux-riscv64-gnu.node')
247261
} else {
248-
nativeBinding = require('@css-inline/css-inline-linux-arm-gnueabihf')
262+
nativeBinding = require('@css-inline/css-inline-linux-riscv64-gnu')
249263
}
250264
} catch (e) {
251265
loadError = e

bindings/javascript/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@
5353
"eslint-plugin-import": "^2.29.1",
5454
"eslint-plugin-prettier": "^5.1.2",
5555
"eslint-plugin-sonarjs": "^0.23.0",
56-
"inline-css": "^4.0.2",
57-
"juice": "^10.0.0",
56+
"inline-css": "^4.0.3",
57+
"juice": "^11.0.3",
5858
"npm-run-all2": "^6.1.1",
5959
"prettier": "^3.1.1",
6060
"typescript": "^5.3.3"

0 commit comments

Comments
 (0)