character table lookup

JavaScript performance comparison

Test case created by David Flanagan

Info

I want to map a character code to a set of related character codes. Is it faster to use a JS object as the set, or to use a string and indexOf()?

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var str = "AB";
    var obj = [];
    obj[65] = obj[66] = true;
   
   
};
</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
object
var x = obj[65];
var y = obj[66];
pending…
string
var x = str.indexOf(String.fromCharCode(65)) !== -1;
var y = str.indexOf(String.fromCharCode(66)) !== -1;
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