Anagrams
JavaScript performance comparison
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.
| Test | Ops/sec | |
|---|---|---|
One-liner |
|
pending… |
Logical |
|
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:
- Revision 1: published
- Revision 7: published
- Revision 8: published
0 comments