File tree Expand file tree Collapse file tree 4 files changed +23
-13
lines changed Expand file tree Collapse file tree 4 files changed +23
-13
lines changed Original file line number Diff line number Diff line change 99## Performance
1010
1111This library uses components from Mozilla's Servo project for CSS parsing and matching.
12- Performance benchmarks show 3-9x faster execution than ` tijsverkoyen/css-to-inline-styles ` .
12+ Performance benchmarks show significant speed improvements over other popular PHP CSS inlining libraries .
1313
14- The table below shows benchmark results comparing ` css_inline ` with ` tijsverkoyen/css-to-inline-styles ` on typical HTML documents:
14+ | | Size | ` css_inline 0.15.0 ` | ` css-to-inline-styles 2.3.0 ` | ` emogrifier 7.3.0 ` |
15+ | -------------------| ---------| ---------------------| ------------------------------| -------------------------|
16+ | Simple | 230 B | 5.99 µs | 28.06 µs (** 4.68x** ) | 137.85 µs (** 23.01x** ) |
17+ | Realistic email 1 | 8.58 KB | 102.25 µs | 313.31 µs (** 3.06x** ) | 637.75 µs (** 6.24x** ) |
18+ | Realistic email 2 | 4.3 KB | 71.98 µs | 655.43 µs (** 9.10x** ) | 2.32 ms (** 32.21x** ) |
19+ | GitHub Page† | 1.81 MB | 163.80 ms | ERROR | ERROR |
1520
16- | | Size | ` css_inline 0.15.0 ` | ` tijsverkoyen/css-to-inline-styles 2.2.7 ` | Speedup |
17- | -------------------| ---------| ---------------------| -------------------------------------------| ---------|
18- | Simple | 230 B | 5.99 µs | 28.06 µs | ** 4.68x** |
19- | Realistic email 1 | 8.58 KB | 102.25 µs | 313.31 µs | ** 3.06x** |
20- | Realistic email 2 | 4.3 KB | 71.98 µs | 655.43 µs | ** 9.10x** |
21- | GitHub Page† | 1.81 MB | 163.80 ms | 8.22 ms* | N/A |
22-
23- > † The GitHub page benchmark uses modern CSS that ` tijsverkoyen/css-to-inline-styles ` cannot process, resulting in skipped styles and an invalid comparison.
21+ † The GitHub page benchmark contains complex modern CSS that neither ` css-to-inline-styles ` nor ` emogrifier ` can process and didn't finish a single iteration in >10 minutes.
2422
2523Please refer to the ` benchmarks/InlineBench.php ` file to review the benchmark code.
2624The results displayed above were measured using stable ` rustc 1.88 ` on PHP ` 8.4.10 ` .
Original file line number Diff line number Diff line change 55use PhpBench \Benchmark \Metadata \Annotations \ParamProviders ;
66use CssInline ;
77use TijsVerkoyen \CssToInlineStyles \CssToInlineStyles ;
8-
8+ use Pelago \ Emogrifier \ CssInliner ;
99
1010class InlineBench
1111{
@@ -16,6 +16,7 @@ public function __construct()
1616 $ this ->cssToInlineStyles = new CssToInlineStyles ();
1717 ini_set ('pcre.backtrack_limit ' , '10000000 ' );
1818 ini_set ('pcre.recursion_limit ' , '10000000 ' );
19+ ini_set ('memory_limit ' , '2048M ' );
1920 }
2021
2122 /**
@@ -34,6 +35,14 @@ public function benchCssToInlineStyles(array $params): void
3435 $ this ->cssToInlineStyles ->convert ($ params ['html ' ]);
3536 }
3637
38+ /**
39+ * @ParamProviders("provideBenchmarkCases")
40+ */
41+ public function benchEmogrifier (array $ params ): void
42+ {
43+ CssInliner::fromHtml ($ params ['html ' ])->inlineCss ()->render ();
44+ }
45+
3746
3847 public function provideBenchmarkCases (): \Generator
3948 {
Original file line number Diff line number Diff line change 88 "ext-css_inline" : " *"
99 },
1010 "require-dev" : {
11+ "pelago/emogrifier" : " ^7.3" ,
1112 "phpbench/phpbench" : " ^1.4" ,
1213 "phpunit/phpunit" : " ^10.5" ,
1314 "tijsverkoyen/css-to-inline-styles" : " ^2.3"
2324 },
2425 "config" : {
2526 "sort-packages" : true ,
26- "optimize-autoloader" : true
27+ "optimize-autoloader" : true ,
28+ "process-timeout" : 0
2729 }
2830}
Original file line number Diff line number Diff line change 33 "runner.path" : " benchmarks" ,
44 "runner.php_config" : {
55 "extension" : " target/release/libcss_inline_php.so"
6- }
6+ },
7+ "runner.timeout" : 3600
78}
You can’t perform that action at this time.
0 commit comments