mathiasbynens / jsperf.com

jsPerf.com source code
http://jsperf.com/
Other
473 stars 56 forks source link

Not getting correct results #225

Closed rickdog closed 9 years ago

rickdog commented 9 years ago

My test at http://jsperf.com/arraybuffer-test is returning results opposite of what I really experience in my browser. Giving 370 ops for "loop" and 190 ops for "apply".

If I run the exact same code in my browser, I get 6.5 ops for "loop" and 200 ops for "apply". Something's fishy here.

The equivalent code:

<script>

// setup
var ab = new ArrayBuffer(100000);
var vw = new Uint8Array(ab);
for (i=0; i<100000; i++)
  vw[i] = i%256;

console.time("apply")
for (x=0;x<100;x++)
{
  var s = String.fromCharCode.apply(null, new Uint8Array(ab));
}
console.timeEnd("apply")

console.time("loop")
for (x=0;x<100;x++)
{
  var s = '';
  var bytes = new Uint8Array(ab);
  var len = bytes.byteLength;
  for (var i = 0; i < len; i++) {
    s += String.fromCharCode(bytes[i]);
  }
}
console.timeEnd("loop")

</script>

jdalton commented 9 years ago

Not likely related to our test harness. String concats are a tricky thing to benchmark as the engine may not commit/flatten the concat until needed, deferring it until then.