Boolean->Int (v9)

Revision 9 of this benchmark created on


Description

Checks the speed of boolean->integer operations

Setup

var b = Math.floor(Math.random() * 2) === 1;

Test runner

Ready to run.

Testing in
TestOps/sec
Ternary Operator, implicit
var i = b ? 1 : 0;
ready
Ternary Operator, explicit
var i = b === true ? 1 : 0;
ready
Auto-box Conversion (+ operator)
var i = +b;
ready
Not-Not (~~ operators)
var i = ~~b;
ready
Bitwise And (&)
var i = b & 1;
ready
Bitwise Or (|)
var i = b | 0;
ready
Bitwise Xor (^)
var i = b ^ 1;
ready
Number()
var i = Number(b);
ready
Multiplication (*)
var i = b * 1
ready
Addition
var i = b + 0;
ready

Revisions

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