Boolean conversion speed (v10)

Revision 10 of this benchmark created by VladimirTechMan on


Setup

var a = [0, 1, "", "tt", false, true, "true", "false", undefined, -0, null, NaN, new Boolean(true), new Boolean(false)];

Test runner

Ready to run.

Testing in
TestOps/sec
Bang bang
var b;
for (var idx = 0; idx < a.length; ++idx) {
  b = !! a[idx];
}
ready
Boolean function
var b;
for (var idx = 0; idx < a.length; ++idx) {
  b = Boolean(a[idx]);
}
ready
AND true
var c;
for (var idx = 0; idx < a.length; ++idx) {
  c = a[idx] && true || false;
}
ready
Bang plus comparison
var c;
for (var idx = 0; idx < a.length; ++idx) {
  c = (!a[idx]) === false;
}
ready

Revisions

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