Best of jsperf (2000-2013) – Part 3/3

Sam Deering

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