jQuery parse times

Orde Saunders' avatarPublished: by Orde Saunders

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.

ConnectionMean parse time (ms)σData points
2G106.0033.5210
3G114.5332.7515
Shared broadband119.4028.9215

jQuery parse times

DeviceBrowserjQuery versionMean parse time (ms)σData points
Galaxy MiniAndroid Browser2.1.0224.73175.2711
Galaxy MiniAndroid Browser1.11.0186.91112.5511
Galaxy Note 2Chrome2.1.090.6420.8014
Galaxy Note 2Chrome1.11.093.1816.6011
Galaxy Note 2Android Browser2.1.0135.0032.3410
Galaxy Note 2Android Browser1.11.0112.4031.1315
Galaxy SAndroid Browser2.1.0218.30157.2910
Galaxy SAndroid Browser1.11.0116.0986.9611
Galaxy S2Android Browser2.1.0139.00102.1613
Galaxy S2Android Browser1.11.0111.4237.5412
Galaxy S3Chrome2.1.085.0032.2610
Galaxy S3Chrome1.11.083.7316.7011
Galaxy S3Android Browser2.1.094.9040.9010
Galaxy S3Android Browser1.11.086.0938.5111
iPadMobile Safari2.1.089.919.0611
iPadMobile Safari1.11.0105.2010.9110
iPad 3Chrome2.1.017.707.4710
iPad 3Chrome1.11.027.7015.3210
iPad 3Mobile Safari2.1.022.908.4310
iPad 3Mobile Safari1.11.021.692.0913
iPad 4Chrome2.1.09.173.7612
iPad 4Chrome1.11.08.892.2118
iPad 4Mobile Safari2.1.013.276.2411
iPad 4Mobile Safari1.11.011.150.8613
iPad Mini (iOS 6)Chrome2.1.031.674.5312
iPad Mini (iOS 6)Chrome1.11.033.202.9610
iPad Mini (iOS 6)Mobile Safari2.1.037.384.2513
iPad Mini (iOS 6)Mobile Safari1.11.041.822.3311
iPhone 3GMobile Safari2.1.0622.6011.5410
iPhone 3GMobile Safari1.11.0701.9113.1711
iPhone 3GSMobile Safari2.1.0174.15100.1913
iPhone 3GSMobile Safari1.11.0159.0016.5711
iPhone 4Chrome2.1.0145.1032.9510
iPhone 4Chrome1.11.0165.1852.6811
iPhone 4Mobile Safari2.1.099.074.8314
iPhone 4Mobile Safari1.11.0125.1020.5210
iPhone 5sChrome2.1.07.103.8610
iPhone 5sChrome1.11.08.303.0710
iPhone 5sMobile Safari2.1.012.104.4410
iPhone 5sMobile Safari1.11.013.934.8914
Kindle Fire HDSilk2.1.053.3622.2711
Kindle Fire HDSilk1.11.054.3618.4111
MacBook AirChrome2.1.012.905.2010
MacBook AirChrome1.11.012.365.8811
Nexus 10Chrome2.1.049.4128.2217
Nexus 10Chrome1.11.044.2420.0617
Nexus 4Chrome2.1.092.0941.8211
Nexus 4Chrome1.11.078.6418.9711
Nexus 7Chrome2.1.079.0026.0010
Nexus 7Chrome1.11.057.236.9413
Nexus OneAndroid Browser2.1.098.0869.1512
Nexus OneAndroid Browser1.11.0120.6476.9711
Nintendo 3DSSystem1.11.01689.7814.229
PS VitaSilk2.1.0102.701.6810
PS VitaSilk1.11.0118.502.9710
Transformer PadChrome2.1.053.6414.0711
Transformer PadChrome1.11.071.2727.3811