Anagrams

JavaScript performance comparison

Revision 7 of this test case created by

Preparation code

<script>
  function ana(str, str2) {
   return Array.prototype.slice.call(str).sort().join('') === Array.prototype.slice.call(str2).sort().join('');
  }
  
  function ana2(str, str2) {
   if (str.length != str2.length) return false;
  
   var table = {};
  
   for (var i = 0; i < str.length; i++) {
    table[str[i]] = table[str[i]] ? table[str[i]] + 1 : 1;
    table[str2[i]] = table[str2[i]] ? table[str2[i]] - 1 : -1;
   }
  
   for (var k in table)
   if (table[k] != 0) return false;
  
   return true;
  }
</script>
    

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
One-liner
ana('hello', 'ehlol');
ana('hellfo', 'ehlol');
ana('hefllo', 'ehlogl');
ana('abcdefghijklmnopqrstuvwxyz0123456789@#$%&*-+()?/;:"!', '!":;/?)(+-*&%$#@9876543210abcdefghijklmnopqrstuvwxyz');
pending…
Logical
ana2('hello', 'ehlol');
ana2('hellfo', 'ehlol');
ana2('hefllo', 'ehlogl');
ana2('abcdefghijklmnopqrstuvwxyz0123456789@#$%&*-+()?/;:"!', '!":;/?)(+-*&%$#@9876543210abcdefghijklmnopqrstuvwxyz');
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.

0 Comments