Anagrams

JavaScript performance comparison

Test case created

Preparation code

<script>
  function ana(str, str2) {
   return str.split('').sort().join('') == str2.split('').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 unknown unknown
Test Ops/sec
One-liner
ana('hello', 'ehlol');
ana('hellfo', 'ehlol');
ana('hefllo', 'ehlogl');
pending…
Logical
ana2('hello', 'ehlol');
ana2('hellfo', 'ehlol');
ana2('hefllo', 'ehlogl');
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. Here’s a list of current revisions for this page:

0 comments

Add a comment