Strange performance difference between V8 and SpiderMonkey

classic Classic list List threaded Threaded
1 message Options
ram
Reply | Threaded
Open this post in threaded view
|

Strange performance difference between V8 and SpiderMonkey

ram
I setup a JSPerf to see if representing a matrix as a 1-dimensional array would be faster than using a 2-D array - http://jsperf.com/fill-2d-vs-1d-array

As you can see in the results, in V8 the 1-D version is 20% faster. But in SpiderMonkey the 1-D version is about 40% slower. I'm trying to understand why this is - I've looked through the docs but am not sure how to get SpiderMonkey CLI to tell me if/how a function is being optimized or not. So I'm wondering if someone here (who knows SpiderMonkey internals) can help..?

I'm attaching the code here below for your convenience:


var rows = 200, cols = 300;


// 2-D version
var matrix = new Array(rows);
var i, j;

for (i=0; i<rows; ++i) {
  matrix[i] = new Array(cols);
 
  for (j=0; j<cols; ++j) {
    matrix[i][j] = (i === j ? 1 : 0);
  }
}


// 1-D version
var matrix = new Array(rows * cols);
var idx, i, j;

for (i=0, idx=0; i<rows; ++i, idx += cols) {
  for (j=0; j<cols; ++j) {
    matrix[idx + j] = (i === j ? 1 : 0);
  }
}
_______________________________________________
dev-tech-js-engine mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-js-engine