array index vs string charAt
JavaScript performance comparison
Preparation code
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/prototype/1/prototype.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/mootools/1.3/mootools-yui-compressed.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/ext-core/3/ext-core.js"></script>
<script>
var str = "g9p87ngyp876ncw65-8ut9-84ttttp1n[8xt[ntg[5nf87y42xn49p54545454mny0t968uy908u9ymi409yikj,obvmy985uv98n7y87fy5786fty6t687t71t76r276bt87y4npt9vhm98phvt9",
arr = str.split("");
</script>script
<script>
Benchmark.prototype.setup = function() {
< script src = "//cdn.ext/library.js" > < /script><script src="/ / cdn.ext / library.js "></script><script src=" //cdn.ext/library.js"></script\ZX
};
Benchmark.prototype.teardown = function() {
> < script src = "//cdn.ext/library.js" > < /script><script src="/ / cdn.ext / library.js "></script><script src=" //cdn.ext/library.js"></script><script src="//cdn.ext/library.js"></script><script src="//cdn.ext/library.js"></script><script src="//cdn.ext/library.js"></script><script src="//cdn.ext/library.js"></script><script src="//cdn.ext/library.js"></script><script src="//cdn.ext/library.js"></script><script src="//cdn.ext/library.js"></script>
};
</script>
Preparation code output
script
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
Test | Ops/sec | |
---|---|---|
array index
|
|
pending… |
string charAt
|
|
pending… |
arr index with split
|
|
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.
- Revision 1: published
- Revision 2: published MikeM
- Revision 3: published
- Revision 5: published
- Revision 6: published
- Revision 7: published
- Revision 8: published
- Revision 9: published
- Revision 10: published
- Revision 11: published
- Revision 12: published
- Revision 13: published
- Revision 14: published
- Revision 15: published
- Revision 16: published
- Revision 17: published
- Revision 18: published
- Revision 19: published
0 Comments