JS Branch Prediction

JavaScript performance comparison

Test case created by Vincent Lee

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  // Generate data
  let arraySize = 32768;
  var dataU = new Array(arraySize);
  var dataS = new Array(arraySize);
  var dataX = new Array(arraySize);
  
  for (let c = 0; c < arraySize; ++c) {
    dataU[c] = Math.round(Math.random() * 256);
    dataS[c] = dataU[c];
    dataX[c] = dataU[c];
  }
  
  dataS.sort((a,b) => { return a > b ? 1 : -1});
  

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Sort and run
dataX.sort((a,b) => { return a > b ? 1 : -1});

// Test
let sum = 0;

// Primary loop
for (let c = 0; c < arraySize; ++c)
{
  if (dataX[c] >= 128)
    sum += dataX[c];
}

console.warn("Sorted: " + sum);
pending…
Use unsorted
// Test
let sum = 0;

// Primary loop
for (let c = 0; c < arraySize; ++c)
{
  if (dataU[c] >= 128)
    sum += dataU[c];
}

console.warn("Unsorted: " + sum);
pending…
Use sorted
// Test
let sum = 0;

// Primary loop
for (let c = 0; c < arraySize; ++c)
{
  if (dataS[c] >= 128)
    sum += dataS[c];
}

console.warn("Sorted: " + sum);
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

0 Comments