BoolToInt (v3)

Revision 3 of this benchmark created on


Description

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

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
val + 0
true + 0;
false + 0;
ready
right shift
true >> 0;
false >> 0;
ready
right shift 2
true >>> 0;
false >>> 0;
ready
left shift
true << 0;
false << 0;
ready
XOR
true ^ 0;
false ^ 0;
ready

Revisions

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