jQuery parse times
The amount of time required to parse jQuery was measured on a variety of devices. On the latest generation it was parsed in less than 100ms but on older devices it can take 250ms or more. No significant difference was found between jQuery 1.11.0 and 2.1.0. iOS outperforms Android devices of a similar age. On iOS, Chrome consistently parsed jQuery faster than Safari.
Introduction
Whilst jQuery has become the de facto browser abstraction library it does come with a performance cost. In addition to the time required to transfer the data over the network, the browser's JavaScript engine must parse the code. On devices with slower processors, and in browsers with less efficient JavaScript engines, this additional overhead can be significant. In order to quantify this data was collected on a variety of devices.
Method
The tests were carried out using a page built to record some information about the device and the parse time information. The page included one of two versions of jQuery - 1.11.0 or 2.1.0 - selected by a query string parameter. The collected data was sent to a logging endpoint on the server via an asynchronous request and stored as JSON. The full server side code is available on GitHub.
For each device tested, the page was re-loaded multiple times for both versions of jQuery. Requesting a reload should ensure that all resources are refreshed from the server making it a fair comparison each time.
Once collected, the data was analysed using a Python script that calculated the mean and the standard deviation (σ).
When measuring the parse time of jQuery it is important to try and eliminate the effect of the network. One method for this would be to include the library in-line with the page and measure the page's load time. However, jQuery is normally included as an external file so measuring the parse time in this situation was considered preferable if possible. When included as an external file measuring the page's load time will be dependent on the network connection as an extra request will be made. In order to accurately assess the time taken to parse jQuery in an external file timers were set at the start and end of the file, immediately before and after the jQuery code:
window.t_start = new Date();
/*! jQuery v1.11.0 | (c) 2005, 2014 jQuery Foundation, Inc. | jquery.org/license */
!function(a,b){"object"==typeof module&&"object"==typeof module.exports?module.exports=a.document?b(a,!0):function(a){if(!a.document)throw new Error("jQuery requires a window with a document");…
window.t_end = new Date();
The difference between the start and end timers was measured on the same device on a variety of network connections to verify that the timings recorded were independent of the network.
Results
Due to the volume of data the results have been moved to an appendix.
The raw data is available on GitHub.
Conclusion
With the timers in the same external file as the jQuery code there were no significantly different results for parse time on different networks indicating that the effect of the network had been successfully eliminated from the measurements.
In general the results are as expected with more modern devices taking less time to parse jQuery - current generation devices generally taking less than 100ms. With the exception of the iPhone 3G and the Nintendo DS, all devices will parse jQuery in less than 250ms on average, however, it is important to note that the deviation on these devices is very high so the actual time in individual cases could be significantly greater.
The iPhone 5S and iPad 4 took less time than a 2012 MacBook Air showing that hand held devices are no longer necessarily slower than their larger counterparts.
Safari on iOS took consistently longer than Chrome on the same device. This is the opposite of what was expected as Chrome uses a WebView which supposedly has lower JavaScript performance. On Android devices, Chrome was consistently faster than the system Browser, which is as expected.
iOS devices out perform Android devices of a similar age, in some cases by a significant margin.
Taken overall, there is no significant difference between the parse times for jQuery 1.11.0 and 2.1.0 despite the latter's slightly smaller file size (95K vs 82K). Whilst there may not be a significant difference in the parse time of the library this does not mean that they are of equivalent performance when it comes to use - this would require additional research to determine.
If you are going to include JavaScript libraries on your pages you should be aware that, on older devices, they may come with a performance overhead beyond that taken to request and transfer the data over the network. To mitigate this you should look at using asynchronous and lazy loading techniques.
Acknowledgements
Thanks to DeviceLab for the use of a number of their devices to improve the test coverage.
Appendix
Network isolation results
These tests were performed with jQuery version 1.11.0 in Chrome on a Galaxy Note 2 running Cyanogen.
Connection | Mean parse time (ms) | σ | Data points |
---|---|---|---|
2G | 106.00 | 33.52 | 10 |
3G | 114.53 | 32.75 | 15 |
Shared broadband | 119.40 | 28.92 | 15 |
jQuery parse times
Device | Browser | jQuery version | Mean parse time (ms) | σ | Data points |
---|---|---|---|---|---|
Galaxy Mini | Android Browser | 2.1.0 | 224.73 | 175.27 | 11 |
Galaxy Mini | Android Browser | 1.11.0 | 186.91 | 112.55 | 11 |
Galaxy Note 2 | Chrome | 2.1.0 | 90.64 | 20.80 | 14 |
Galaxy Note 2 | Chrome | 1.11.0 | 93.18 | 16.60 | 11 |
Galaxy Note 2 | Android Browser | 2.1.0 | 135.00 | 32.34 | 10 |
Galaxy Note 2 | Android Browser | 1.11.0 | 112.40 | 31.13 | 15 |
Galaxy S | Android Browser | 2.1.0 | 218.30 | 157.29 | 10 |
Galaxy S | Android Browser | 1.11.0 | 116.09 | 86.96 | 11 |
Galaxy S2 | Android Browser | 2.1.0 | 139.00 | 102.16 | 13 |
Galaxy S2 | Android Browser | 1.11.0 | 111.42 | 37.54 | 12 |
Galaxy S3 | Chrome | 2.1.0 | 85.00 | 32.26 | 10 |
Galaxy S3 | Chrome | 1.11.0 | 83.73 | 16.70 | 11 |
Galaxy S3 | Android Browser | 2.1.0 | 94.90 | 40.90 | 10 |
Galaxy S3 | Android Browser | 1.11.0 | 86.09 | 38.51 | 11 |
iPad | Mobile Safari | 2.1.0 | 89.91 | 9.06 | 11 |
iPad | Mobile Safari | 1.11.0 | 105.20 | 10.91 | 10 |
iPad 3 | Chrome | 2.1.0 | 17.70 | 7.47 | 10 |
iPad 3 | Chrome | 1.11.0 | 27.70 | 15.32 | 10 |
iPad 3 | Mobile Safari | 2.1.0 | 22.90 | 8.43 | 10 |
iPad 3 | Mobile Safari | 1.11.0 | 21.69 | 2.09 | 13 |
iPad 4 | Chrome | 2.1.0 | 9.17 | 3.76 | 12 |
iPad 4 | Chrome | 1.11.0 | 8.89 | 2.21 | 18 |
iPad 4 | Mobile Safari | 2.1.0 | 13.27 | 6.24 | 11 |
iPad 4 | Mobile Safari | 1.11.0 | 11.15 | 0.86 | 13 |
iPad Mini (iOS 6) | Chrome | 2.1.0 | 31.67 | 4.53 | 12 |
iPad Mini (iOS 6) | Chrome | 1.11.0 | 33.20 | 2.96 | 10 |
iPad Mini (iOS 6) | Mobile Safari | 2.1.0 | 37.38 | 4.25 | 13 |
iPad Mini (iOS 6) | Mobile Safari | 1.11.0 | 41.82 | 2.33 | 11 |
iPhone 3G | Mobile Safari | 2.1.0 | 622.60 | 11.54 | 10 |
iPhone 3G | Mobile Safari | 1.11.0 | 701.91 | 13.17 | 11 |
iPhone 3GS | Mobile Safari | 2.1.0 | 174.15 | 100.19 | 13 |
iPhone 3GS | Mobile Safari | 1.11.0 | 159.00 | 16.57 | 11 |
iPhone 4 | Chrome | 2.1.0 | 145.10 | 32.95 | 10 |
iPhone 4 | Chrome | 1.11.0 | 165.18 | 52.68 | 11 |
iPhone 4 | Mobile Safari | 2.1.0 | 99.07 | 4.83 | 14 |
iPhone 4 | Mobile Safari | 1.11.0 | 125.10 | 20.52 | 10 |
iPhone 5s | Chrome | 2.1.0 | 7.10 | 3.86 | 10 |
iPhone 5s | Chrome | 1.11.0 | 8.30 | 3.07 | 10 |
iPhone 5s | Mobile Safari | 2.1.0 | 12.10 | 4.44 | 10 |
iPhone 5s | Mobile Safari | 1.11.0 | 13.93 | 4.89 | 14 |
Kindle Fire HD | Silk | 2.1.0 | 53.36 | 22.27 | 11 |
Kindle Fire HD | Silk | 1.11.0 | 54.36 | 18.41 | 11 |
MacBook Air | Chrome | 2.1.0 | 12.90 | 5.20 | 10 |
MacBook Air | Chrome | 1.11.0 | 12.36 | 5.88 | 11 |
Nexus 10 | Chrome | 2.1.0 | 49.41 | 28.22 | 17 |
Nexus 10 | Chrome | 1.11.0 | 44.24 | 20.06 | 17 |
Nexus 4 | Chrome | 2.1.0 | 92.09 | 41.82 | 11 |
Nexus 4 | Chrome | 1.11.0 | 78.64 | 18.97 | 11 |
Nexus 7 | Chrome | 2.1.0 | 79.00 | 26.00 | 10 |
Nexus 7 | Chrome | 1.11.0 | 57.23 | 6.94 | 13 |
Nexus One | Android Browser | 2.1.0 | 98.08 | 69.15 | 12 |
Nexus One | Android Browser | 1.11.0 | 120.64 | 76.97 | 11 |
Nintendo 3DS | System | 1.11.0 | 1689.78 | 14.22 | 9 |
PS Vita | Silk | 2.1.0 | 102.70 | 1.68 | 10 |
PS Vita | Silk | 1.11.0 | 118.50 | 2.97 | 10 |
Transformer Pad | Chrome | 2.1.0 | 53.64 | 14.07 | 11 |
Transformer Pad | Chrome | 1.11.0 | 71.27 | 27.38 | 11 |