String Partition

Benchmark created by Cat Chen on


Setup

var input = 'abcdefghijklmn:123456';
    var output;

Test runner

Ready to run.

Testing in
TestOps/sec
RegExp
output = input.match(/^[^:]*/)[0];
ready
Sub String
output = input.indexOf(':') < 0 ? input : input.substr(0, input.indexOf(':'))
ready
Split
output = input.split(':')[0]
ready
Sub String with Cache
var index = input.indexOf(':');
output = index < 0 ? input : input.substr(0, index)
ready

Revisions

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

  • Revision 1: published by Cat Chen on