Javascript check boolean string via .toUpperCase() vs .toLowerCase() vs regex (v10)

Revision 10 of this benchmark created by elennaro on


Setup

var allLower = "true";
    var allUpper = "TRUE";
    var mixed = "True";
    var searchstring = "True";

Test runner

Ready to run.

Testing in
TestOps/sec
lower to upper
allLower.toUpperCase() === 'TRUE';
ready
upper to upper
allUpper.toUpperCase() === 'TRUE';
ready
mixed to upper
mixed.toUpperCase() === 'TRUE';
ready
lower to lower
allLower.toLowerCase() === 'true';
ready
upper to lower
allUpper.toLowerCase() === 'true';
ready
mixed to lower
mixed.toLowerCase() === 'true';
ready
regex allUpper
(/^true$/i).test(allUpper);
ready
regex mixed
(/^true$/i).test(mixed);
ready
regex lower
(/^true$/i).test(allLower);
ready
regex from string allUpper
new RegExp(searchstring, "i").test(allUpper);
ready
regex from string mixed
new RegExp(searchstring, "i").test(mixed);
ready
regex from string allLower
new RegExp(searchstring, "i").test(allLower);
ready

Revisions

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