substring vs match 2

Benchmark created by mdomba on


Setup

var str1 = "columnId",
        str2 = "columnId[]";

Test runner

Ready to run.

Testing in
TestOps/sec
substring, not found
t1 = (str1.substring(str1.length - 2) === '[]') ? str1 : str1+'[]';
 
ready
match, not found
t1 = (str1.match(/.+\[\]$/)) ? str1 : str1+'[]';
 
ready
substring, found
t2 = (str2.substring(str2.length - 2) === '[]') ? str2 : str2+'[]';
 
ready
match, found
t2 = (str2.match(/.+\[\]$/)) ? str2 : str2+'[]';
 
ready

Revisions

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

  • Revision 1: published by mdomba on