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 9
9
## Performance
10
10
11
11
This 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 .
13
13
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 |
15
20
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.
24
22
25
23
Please refer to the ` benchmarks/InlineBench.php ` file to review the benchmark code.
26
24
The 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 5
5
use PhpBench \Benchmark \Metadata \Annotations \ParamProviders ;
6
6
use CssInline ;
7
7
use TijsVerkoyen \CssToInlineStyles \CssToInlineStyles ;
8
-
8
+ use Pelago \ Emogrifier \ CssInliner ;
9
9
10
10
class InlineBench
11
11
{
@@ -16,6 +16,7 @@ public function __construct()
16
16
$ this ->cssToInlineStyles = new CssToInlineStyles ();
17
17
ini_set ('pcre.backtrack_limit ' , '10000000 ' );
18
18
ini_set ('pcre.recursion_limit ' , '10000000 ' );
19
+ ini_set ('memory_limit ' , '2048M ' );
19
20
}
20
21
21
22
/**
@@ -34,6 +35,14 @@ public function benchCssToInlineStyles(array $params): void
34
35
$ this ->cssToInlineStyles ->convert ($ params ['html ' ]);
35
36
}
36
37
38
+ /**
39
+ * @ParamProviders("provideBenchmarkCases")
40
+ */
41
+ public function benchEmogrifier (array $ params ): void
42
+ {
43
+ CssInliner::fromHtml ($ params ['html ' ])->inlineCss ()->render ();
44
+ }
45
+
37
46
38
47
public function provideBenchmarkCases (): \Generator
39
48
{
Original file line number Diff line number Diff line change 8
8
"ext-css_inline" : " *"
9
9
},
10
10
"require-dev" : {
11
+ "pelago/emogrifier" : " ^7.3" ,
11
12
"phpbench/phpbench" : " ^1.4" ,
12
13
"phpunit/phpunit" : " ^10.5" ,
13
14
"tijsverkoyen/css-to-inline-styles" : " ^2.3"
23
24
},
24
25
"config" : {
25
26
"sort-packages" : true ,
26
- "optimize-autoloader" : true
27
+ "optimize-autoloader" : true ,
28
+ "process-timeout" : 0
27
29
}
28
30
}
Original file line number Diff line number Diff line change 3
3
"runner.path" : " benchmarks" ,
4
4
"runner.php_config" : {
5
5
"extension" : " target/release/libcss_inline_php.so"
6
- }
6
+ },
7
+ "runner.timeout" : 3600
7
8
}
You can’t perform that action at this time.
0 commit comments