binding vs storing reference

JavaScript performance comparison

Test case created by Noxoc

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var canvas = document.createElement("canvas")
      , context = canvas.getContext("2d")
    ;
   
    function draw(canvas, context) {
      context.clearRect(0,0,canvas.width,canvas.height);
      context.fillRect(0,0, canvas.width, canvas.height);
    }
   
    var boundDraw = draw.bind(draw, canvas, context);
   
    document.body.appendChild(canvas);
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Passing Arguments
draw(canvas, context);
pending…
Shortcut using Function.bind
boundDraw();
pending…

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

Compare results of other browsers

0 comments

Add a comment