You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+72-10Lines changed: 72 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,14 @@
1
-
# CSS-in-js Performance tests
1
+
# CSS-in-JS Performance Tests
2
2
3
-
Testing a couple of CSS in JS libraries, check [the source folder](./src/cases) for the different tests.
3
+
Testing a couple of CSS-in-JS libraries, check [the source folder](./src/) for the different tests.
4
4
5
-
And read why we did these tests [here](https://engineering.hellofresh.com/the-css-in-js-battle-89c34a7a83ea).
5
+
And read why we did these tests in the [CSS-in-JS Battle](https://engineering.hellofresh.com/the-css-in-js-battle-89c34a7a83ea) article.
6
6
7
7
## Usage
8
8
9
9
You can clone this repository, `npm install` and run `npm run bench` to run the tests yourself.
10
10
11
-
To set the amount of iterations you can set an environment variable called `ITERATIONS`. This will result in: `ITERATIONS=100 npm run bench`.
11
+
To set the amount of iterations (see below) you can set an environment variable called `ITERATIONS`. This will result in: `ITERATIONS=100 npm run bench`.
12
12
13
13
> Make sure you have Node6 or higher installed as well.
14
14
@@ -38,7 +38,7 @@ Hardware:
38
38
39
39
## Results
40
40
41
-
The first test is just a simple render test, generate 2 class names, one for a container and one for a button.
41
+
The first test is just a simple render test, generates two classes, one for a container and one for a button.
42
42
43
43
```
44
44
Running simple test.
@@ -53,7 +53,6 @@ jss length 447
53
53
jss-without-preset length 443
54
54
styletron length 366
55
55
56
-
57
56
aphrodite x 9,421 ops/sec ±11.15% (61 runs sampled)
58
57
cxs x 21,834 ops/sec ±9.34% (65 runs sampled)
59
58
cxs-optimized x 17,377 ops/sec ±3.65% (76 runs sampled)
@@ -67,7 +66,7 @@ styletron length 366
67
66
Fastest is: fela
68
67
```
69
68
70
-
The second test overloads on styles, so it adds `n (ITERATIONS)` amount of different styles for the button.
69
+
The second test overloads on styles, so it adds `n (ITERATIONS)` amount of different styles with a common part for the buttons. Show which libraries can detect the common part and isolate it.
71
70
72
71
```
73
72
Running styles overload test.
@@ -81,7 +80,6 @@ cxs-optimized length 2337
81
80
styletron length 1370
82
81
fela length 1349
83
82
84
-
8 tests completed.
85
83
86
84
aphrodite x 1,446 ops/sec ±2.55% (69 runs sampled)
87
85
jss x 3,160 ops/sec ±2.85% (75 runs sampled)
@@ -95,7 +93,7 @@ fela length 1349
95
93
Fastest is: fela,styletron
96
94
```
97
95
98
-
The third test overloads on class names, so it adds `n (ITERATIONS)` amount of different class names with the same styles. This test is interesting to see which library actually merges these styles when they're similar.
96
+
The third test overloads on classes, so it adds `n (ITERATIONS)` amount of different class names with the same styles. This test is interesting to see which library actually merges these styles when they're identical.
99
97
100
98
```
101
99
Running classes overload test.
@@ -124,7 +122,7 @@ styletron length 960
124
122
Fastest is: fela
125
123
```
126
124
127
-
The fourth test is about media queries and pseudo-styles.
125
+
The fourth test is about media queries and pseudo-styles with nested style objects.
128
126
129
127
```
130
128
Running nested test.
@@ -155,6 +153,8 @@ Fastest is: styletron
155
153
156
154
### Bundle sizes
157
155
156
+
Launch with `npm run bundle`.
157
+
158
158
```
159
159
Size styletron 2.652KB
160
160
Size cxs 9.766KB
@@ -166,6 +166,68 @@ Size glamor 35.436KB
166
166
Size aphrodite 18.919KB
167
167
```
168
168
169
+
### View generated code
170
+
171
+
Launch with `npm run view`.
172
+
173
+
Find the generated HTML files with their embeded CSS for each test in the `output` directory.
174
+
175
+
Some observations:
176
+
177
+
For all of them, class name is stable between generations if same content. Unless said otherwise, the generated CSS is minimized.
178
+
179
+
#### aphrodite
180
+
181
+
(simple) Removes a non-used class. Generates class names like `original-name_1fm03kj`. Adds `!important` to each CSS property, but this can be deactivated.
182
+
(style overload) Different classes with a common style are kept as is.
183
+
(classes overload) Doesn't detect identical classes that remain duplicate.
184
+
(nested) Manages pseudo-classes and media queries.
185
+
186
+
#### cxs and cxs-optimized
187
+
188
+
(simple) Doesn't remove a non-used class. Generates class names like `cxs-4211614354`.
189
+
(style overload) Different classes with a common style are kept as is. Minimized CSS.
190
+
(classes overload) Detects identical classes that are merged.
191
+
(nested) Manages pseudo-classes and media queries.
192
+
193
+
cxs-optimized can generate some specialized classes (with names like `cxs-display-block` or `cxs-text-align-center`) removed from the classes using these styles and added to elements using them. Seems limited to properties with a small number of possible values. Named colors are not deduplicated.
194
+
195
+
#### fela
196
+
197
+
(simple) Removes a non-used class. Generates class names like `a`, `b`, `c`. Each class has one property only, they are merged at element level.
198
+
(style overload) Styles common to several classes go to classes added to all corresponding elements.
199
+
(classes overload) Detects identical classes that are merged.
200
+
(nested) Manages pseudo-classes and media queries.
201
+
202
+
#### free-style
203
+
204
+
(simple) Doesn't remove a non-used class. Generates class names like `f1lzwo7y`.
205
+
(style overload) Different classes with a common style are kept as is.
206
+
(classes overload) Detects identical classes that are merged.
207
+
(nested) Manages pseudo-classes and media queries.
208
+
209
+
#### glamor
210
+
211
+
(simple) Doesn't remove a non-used class. Generates class names like `css-h433f4`. Add selectors like `[data-css-h433f4]`.
212
+
(style overload) Different classes with a common style are kept as is.
213
+
(classes overload) Detects identical classes that are merged.
214
+
(nested) Manages pseudo-classes and media queries. Adds selectors like `css-1u8v7v4[data-simulate-hover]`.
215
+
216
+
#### jss and jss-without-preset
217
+
218
+
(simple) Doesn't remove a non-used class. Generates class names like `original-name-3553477605`. CSS is formatted and indented (1 space).
219
+
(style overload) Different classes with a common style are kept as is.
220
+
(classes overload) Doesn't detect identical classes that remain duplicate.
221
+
(nested) Manages pseudo-classes and media queries.
222
+
223
+
#### styletron
224
+
225
+
(simple) Doesn't remove a non-used class. Generates class names like `a`, `b`, `c`. Each class has one property only, they are merged at element level (starts with a space).
226
+
(style overload) Styles common to several classes go to classes added to all corresponding elements.
227
+
(classes overload) Detects identical classes that are merged.
228
+
(nested) Manages pseudo-classes and media queries.
"bench": "npm run compile && npm run bench:simple-test && npm run bench:nested-test && npm run bench:style-overload-test && npm run bench:classes-overload-test",
"view": "rimraf output/ && npm run view:simple-test && npm run view:nested-test && npm run view:style-overload-test && npm run view:classes-overload-test",
0 commit comments