Parsing booleans (v2)

Revision 2 of this benchmark created on


Description

Parsing boolean variables from string

Setup

var booleanAsString = 'tRuE';

function stringToBoolean(str){
  return str.toLowerCase() === 'true';
}

String.prototype.toBoolean = function(){
  return this.toLowerCase() === 'true';
}

Test runner

Ready to run.

Testing in
TestOps/sec
Simple comparison
const booleanAsBoolean = booleanAsString.toLowerCase() === 'true';
ready
Simple comparison, as a function
const booleanAsBoolean = stringToBoolean(booleanAsString);
ready
Simple comparison, as a prototype method
const booleanAsBoolean = booleanAsString.toBoolean()
ready
JSON.parse
const booleanAsBoolean = JSON.parse(booleanAsString.toLowerCase())
ready

Revisions

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