Slice vs Substr vs Substring Methods
JavaScript performance comparison
Info
This is comparing the runtimes of substr, substring, and slice in a string for large (10000 character) string size.
Preparation code
<script type="text/javascript">
var longString = "";
// Large = 10,000
for (var i = 0; i < 10000; i++) {
longString += i % 10;
}
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Substring (long) |
|
pending… |
Slice (long) |
|
pending… |
Substr (long) |
|
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
1 comment
Chrome 4.1.249 = xScope Pro 6.43.1 (Android 2.3) Android 2.3.7 = Default Android Browser Fennex 10.0 = Firefox Beta (Android 2.3)
Android device used is a Nexus S 4G