JSFiddle - React, Tailwind, and code Playground

by radu

JavaScript

var x1 = 0, x2 = 50, nX1 = 100, nX2 = 150;
var test, start, time;

start = (new Date).getTime();

for (var i=0; i <= 100000; i++) {
    test = [x1,x2,nX1,nX2].sort(function(a,b){return a - b});
}

time = (new Date).getTime() - start;

console.log(time);


start = (new Date).getTime();

for (var i=0; i <= 100000; i++) {
    test = [x1,x2,nX1,nX2].sort(sorter);
}

time = (new Date).getTime() - start;
console.log(time);

function sorter(a,b) {
    return a - b;
}