encryptlookup

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var alphabet = 'abcdefghijklmnopqrstuvzxyz';
    var words = "keep the winter chill away with this lightweight yet warm baselayer Oasis uses light smooth merino wool in a close fitting enhanced cut to provide comfort";
   
    var wordarray = words.split(" ");
    var code = 'bath';
};
</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 lookup = {};
for (var i = 0; i < alphabet.length; i++) {
  lookup[alphabet.charAt(i)] = wordarray[i];
}

for (var i = 0, len = code.length; i < len; i++) {
  console.log(lookup[code.charAt(i)]);
}
pending…
indexOf
for (var i = 0, len = code.length; i < len; i++) {
  console.log(wordarray[alphabet.indexOf(code.charAt(i))]);
}
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