BoolToInt (v5)

Revision 5 of this benchmark created on


Description

Which option is best performance-wise to convert boolean to integer?

Setup

var map = {};
    map[false] = 0;
    map[true] = 1;

Test runner

Ready to run.

Testing in
TestOps/sec
value ? 1 : 0;
true ? 1 : 0;
false ? 1 : 0;
ready
Unary operator
+true;
+false;
ready
Number function
Number(true);
Number(false);
ready
value | 0
true | 0;
false | 0;
ready
~~(val)
~~(true);
~~(false);
ready
val === true ? 1 : 0
true === true ? 1 : 0;
false === true ? 1 : 0;
ready
val == true ? 1 : 0
true == true ? 1 : 0;
false == true ? 1 : 0;
ready
map
map[true];
map[false]
ready

Revisions

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