bytes bounds check

JavaScript performance comparison

Revision 6 of this test case created by Folkert de Vries

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var buffer = new ArrayBuffer(8);
  
  var view = new DataView(buffer);
  view.setInt32(0, 42); 
  view.setInt32(4, 84); 
  
  function getRandomIntInclusive(min, max) {
    min = Math.ceil(min);
    max = Math.floor(max);
    return Math.floor(Math.random() * (max - min + 1)) + min; //The maximum is inclusive and the minimum is inclusive 
  }
  
  
  
  
  window.y = 0;

};
</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
with try/catch (invalid)
var invalidOffset = getRandomIntInclusive(5,8);
try {
    window.y = view.getInt32(invalidOffset);
} catch (e) {}
pending…
with bounds check (invalid)
var invalidOffset = getRandomIntInclusive(5,8);
if (invalidOffset + 4 <= buffer.byteLength) {
   window.y = view.getInt32(invalidOffset);
}
pending…
with try/catch (valid)
var validOffset = getRandomIntInclusive(0,4);
try {
    window.y = view.getInt32(validOffset);
} catch (e) {}
pending…
baseline
var validOffset = getRandomIntInclusive(0,4);
window.y = view.getInt32(validOffset);
pending…
with bounds check (valid)
var validOffset = getRandomIntInclusive(0,4);
if (validOffset + 4 <= buffer.byteLength) {
   window.y = view.getInt32(validOffset);
}
pending…

Compare results of other browsers

Revisions

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

0 Comments