box intersect

JavaScript performance comparison

Revision 2 of this test case created by ly tran

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var BB = function (width, height, x, y) {
        var hw = width / 2.0;
        var hh = height / 2.0;
   
        this.l = -hw + x;
        this.b = -hh + y;
        this.r = hw + x;
        this.t = hh + y;
    };
   
    BB.prototype.intersects1 = function (b) {
        var a = this;
        return (a.l <= b.r && b.l <= a.r && a.b <= b.t && b.b <= a.t);
    };
   
    BB.prototype.intersects2 = function (b) {
        var a = this;
        return !(a.l > b.r || b.l > a.r || a.b > b.t || b.b > a.t);
    };
   
    BB.prototype.not_intersects = function (b) {
        var a = this;
        return (a.l > b.r || b.l > a.r || a.b > b.t || b.b > a.t);
    };
   
    var random = function(min, max) {
       if (!(max)) {
           max = min
           min = 0
       }
   
       return min + Math.random() * (max - min)
    }
   
    var bb1 = new BB(100, 100, 0, 0)
    var bb2 = new BB(100, 100, 50, 50)
    var bb3 = new BB(100, 100, 200, 200)
    var bb4 = new BB(100, 100, -200, -200)
};
</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
1
bb1.intersects1(bb2)
bb1.intersects1(bb3)
bb1.intersects1(bb4)
pending…
2
bb1.intersects2(bb2)
bb1.intersects2(bb3)
bb1.intersects2(bb4)
pending…
3
bb1.not_intersects(bb2)
bb1.not_intersects(bb3)
bb1.not_intersects(bb4)
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. Here’s a list of current revisions for this page:

0 comments

Add a comment