sidanmor

Software Engineering Blog (for pre/post Javascript Ninjas)

Follow publication

Javascript Performance Test

--

Have you ever wondered which “String to Integer conversion” is faster?

Number('6'); // ?

parseInt('6'); // ?

+'6'; // ?

Or, which comparison operator is faster? == or ===

3 == '3'; // ?

3 === '3'; // ?

Or maybe this is faster?

!!(3 - '3'); // ?

Now you can test it with the new Javascript-Performance-Test I have created.

The “Commons” section runs just one time, before the two tests, and the return object will be passed to the tested function as the first parameter. Each function will run many times, multiple by ten until one second is passed. The results will appear at the title, and the winner will be announced.

Here are more examples:

function nested(arg1, arg2) {
function helper(arg) {
return arg + 1;
}

return helper(arg1) + helper(arg2);
}

Or:

var iife = (function() {
function helper(arg) {
return arg + 1;
}

return function(arg1, arg2) {
return helper(arg1) + helper(arg2);
}
})();
function doArguments() {
var k = 0;
for (var i = 0, j = arguments.length; i < j; i++){
k += arguments[i];
}
return k;
}

Or:

function doArray(array) {
var k = 0;
for (var i = 0, j = array.length; i < j; i++){
k += array[i];
}
return k;
}

--

--

Published in sidanmor

Software Engineering Blog (for pre/post Javascript Ninjas)

Written by Idan Mor (sidanmor)

Full-Stack Team Leader, Senior Full-Stack Software Engineer and Javascript Ninja

No responses yet