BoolToInt

Benchmark created by Gal 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

Revisions

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