BitVec performance

JavaScript performance comparison

Test case created

Preparation code

<script>
function BitVec(init) {
        this.data = new Int32Array(init);
        return this;
}

BitVec.prototype.ishiftor1 = function(mask, shift) {
        var toshift = shift&31;
        var low = mask << toshift;
        this.data[shift>>5] |= low;
        if (toshift) {
                high = mask >> (32 - toshift);
                this.data[(shift>>5)+1] |= high;
        }
}

BitVec.prototype.ishiftor2 = function(mask, shift) {
        var toshift = shift&31;
        var low = mask << toshift;
        this.data[shift>>5] |= low;
        if (toshift) {
                high = mask >> (32 - toshift);
    if (high) {
                    this.data[(shift>>5)+1] |= high;
    }
        }
}
</script>
<script>
Benchmark.prototype.setup = function() {
   
    var vec = new BitVec([32, 41, 63, 43, 62]);
};
</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
ishiftor1
for (var i = 0; i < 50; i++) {
  for (var j = 0; j < 50; j++) {
    vec.ishiftor1(i, j);
  }
}
pending…
ishiftor2
for (var i = 0; i < 50; i++) {
  for (var j = 0; j < 50; j++) {
    vec.ishiftor2(i, j);
  }
}
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