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

Revision 111 of this benchmark created by hin on


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.