Boolean conversion speed (v7)

Revision 7 of this benchmark created by Ari Porad 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

Revisions

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