Skip to content

Commit 336b0f9

Browse files
committed
update react render comparison with new benchmark project
1 parent 8718c25 commit 336b0f9

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed

src/guide/comparison.md

+45-3
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,51 @@ When rendering UI, manipulating the DOM is typically the most expensive operatio
3333

3434
In React, let's say the additional overhead of rendering an element is 1 and the overhead of an average component is 2. In Vue, the overhead of an element would be more like 0.1, but the overhead of an average component would be 4, due to the setup required for our reactivity system.
3535

36-
This means that in typical applications, where there are many more elements than components being rendered, Vue will outperform React by a significant margin. To demonstrate this, let's render a list of 10,000 items in a single component. In Chrome 52 on my 2014 Macbook Air, [Vue renders](https://jsfiddle.net/chrisvfritz/859gL422/) in an average of 60ms, while [React renders](https://jsfiddle.net/chrisvfritz/65ojbkab/) in an average of 127ms.
37-
38-
In extreme cases however, such as using 1 normal component to render each element, Vue will usually be slower. When modifying the previous examples accordingly, [Vue renders](https://jsfiddle.net/chrisvfritz/mk8jaqpg/) in ~585ms, while [React renders](https://jsfiddle.net/chrisvfritz/2sx0341o/) in ~157ms! This isn't the end of the story though. Both Vue and React offer functional components, which are preferred in situations like this. Since functional components are closer to the cost of elements, Vue is once again on top, with [~73ms](https://jsfiddle.net/chrisvfritz/413wjqyf/) vs [~144ms](https://jsfiddle.net/chrisvfritz/kss01xg7/) - and this performance boost only required adding a single line for Vue: `functional: true`.
36+
This means that in typical applications, where there are many more elements than components being rendered, Vue will outperform React by a significant margin. In extreme cases however, such as using 1 normal component to render each element, Vue will usually be slower. This isn't the end of the story though.
37+
38+
Both Vue and React also offer functional components, which are stateless and instanceless - and therefore, require less overhead. When these are used in performance-critical situations, Vue is once again faster. To demonstrate this, we built a simple [benchmark project](https://github.com/chrisvfritz/vue-render-performance-comparisons) that just renders 10,000 list items 100 times. We encourage you to try it yourself, as the results will vary depending on the hardware and browser used - and actually, they'll vary even between runs due to the nature of JavaScript engines.
39+
40+
If you're feeling lazy though, below are the numbers from one run in Chrome 52 on a 2014 MacBook Air. To avoid cherry-picking, both benchmarks were actually run 20 separate times, with results from the best runs included below:
41+
42+
{% raw %}
43+
<table class="benchmark-table">
44+
<thead>
45+
<tr>
46+
<th></th>
47+
<th>Vue</th>
48+
<th>React</th>
49+
</tr>
50+
</thead>
51+
<tbody>
52+
<tr>
53+
<th>Fastest</th>
54+
<td>23ms</td>
55+
<td>63ms</td>
56+
</tr>
57+
<tr>
58+
<th>Median</th>
59+
<td>42ms</td>
60+
<td>81ms</td>
61+
</tr>
62+
<tr>
63+
<th>Average</th>
64+
<td>51ms</td>
65+
<td>94ms</td>
66+
</tr>
67+
<tr>
68+
<th>95th Perc.</th>
69+
<td>73ms</td>
70+
<td>164ms</td>
71+
</tr>
72+
<tr>
73+
<th>Slowest</th>
74+
<td>343ms</td>
75+
<td>453ms</td>
76+
</tr>
77+
</tr>
78+
</tbody>
79+
</table>
80+
{% endraw %}
3981

4082
#### Update Performance
4183

themes/vue/source/css/_demo.styl

+10
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,13 @@ ul#demo, ul.demo
4545
@media screen and (max-width: 720px)
4646
#demo, .demo
4747
margin-left 0
48+
49+
.benchmark-table
50+
margin: 0 auto
51+
text-align center
52+
53+
tbody > tr > th
54+
text-align right
55+
56+
th, td
57+
padding: 3px 7px

0 commit comments

Comments
 (0)