Slice vs Substr vs Substring vs [ ] Methods
JavaScript performance comparison
Info
This is comparing the runtimes of [ ], substr, substring, and slice in a string for large (66000 character) string size.
Preparation code
<script type="text/javascript">
var longString = "";
// Large = 66,000
for (var i = 0; i < 66000; i++) {
longString += i % 10;
}
var len = 4;
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Substring |
|
pending… |
Slice |
|
pending… |
Substr |
|
pending… |
[ ] (array) |
|
pending… |
charAt (array) |
|
pending… |
[ ] (string) |
|
pending… |
charAt (string) |
|
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 by Kon P and last updated
- Revision 2: published
- Revision 3: published
- Revision 4: published
- Revision 5: published
- Revision 6: published by klaus lynggard hougesen
- Revision 7: published by Aaron Patterson
- Revision 8: published
- Revision 11: published
- Revision 12: published
- Revision 13: published
- Revision 14: published
0 comments