Part 3 of the jsperf best of. Enjoy!

Miscellaneous Speed Tests

jQuery Chaining

Tests whether chaining jQuery function calls is noticeably faster than separate calls. Chaining makes little difference to code performance

Ternary Operators

Check what is faster, reassigning the same value/object to a variable, or changing its value with an if. See JavaScript Shorthand Techniques to improve your shorthand knowledge.

Global Variables vs Local Variables

Another reason not to use global variables.

Try/Catch Error Check Undefined

If vs. Switch

Comparing a if vs. a switch statement. switch is faster?

A closer look at jQuery $.empty()


//Empty function from jQuery 1.9
    empty: function() {
        var elem,
            i = 0;

        for ( ; (elem = this[i]) != null; i++ ) {
            // Remove element nodes and prevent memory leaks
            if ( elem.nodeType === 1 ) {
                jQuery.cleanData( getAll( elem, false ) );

            // Remove any remaining nodes
            while ( elem.firstChild ) {
                elem.removeChild( elem.firstChild );

            // If this is a select, ensure that it displays empty (#12336)
            // Support: IE<9
            if ( elem.options && jQuery.nodeName( elem, "select" ) ) {
                elem.options.length = 0;

        return this;

Other interesting jsperfs

  • The slowest thing ever vs the fastest thing ever
  • 2 ways of getting timestamp
  • Good overview of the speed of the $.map() function
  • Good look at the different MD5 security encrption methods
  • Number formatting 1,000,000
  • Slice vs substring vs substr – pretty much the same
Sam Deering is a Front-end Web Developer who specialises in JavaScript & jQuery. Sam is driven and passionate about sharing his knowledge to educate others.

Free Guide:

How to Choose the Right Charting Library for Your Application

How do you make sure that the charting library you choose has everything you need? Sign up to receive this detailed guide from FusionCharts, which explores all the factors you need to consider before making the decision.

No Reader comments

Special Offer
Free course!

Git into it! Bonus course Introduction to Git is yours when you take up a free 14 day SitePoint Premium trial.