Slice vs Substr vs Substring vs [ ] Methods (v110)

Revision 110 of this benchmark created by hin on


Description

This is comparing the runtimes of substr, substring, and slice in a string for large (10000 character) string size.

Setup

var str = Array.apply(null, Array(100)).map (() => String.fromCharCode(Math.round(Math.random() * 100) % 96 + 32)).join('');
    
    var key = String.fromCharCode(Math.round(Math.random() * 100) % 96 + 32));

Test runner

Ready to run.

Testing in
TestOps/sec
Substring
str.substring(str.indexOf(key));
ready
substr
str.substr(str.indexOf(key));
ready
slice
str.slice(str.indexOf(key));
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.