Vector-vs-string

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var compare_ind = 1+2<<5+3<<(5*2)
    var compare_pos = [1, 2, 3]
    var compare_str = '1|2|3'
};

Benchmark.prototype.teardown = function() {
    if (result != true) alert('error!')
};
</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
Index
var v = [1, 2, 3]
var mask = (1 << 5) - 1
var ind = (v[0] & mask) + (v[1] & mask) << 5 + (v[2] & mask) << (5*2)
var result = compare_ind == ind
pending…
Pos
var v = [1, 2, 3]
var result = compare_pos[0] == v[0] && compare_pos[1] == v[1] && compare_pos[2] == v[2]
pending…
String
var v = [1, 2, 3]
var str = v[0] + '|' + v[1] + '|' + v[2]
var result = compare_str == str
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