Boolean->Int (v7)

Revision 7 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
Number Function
var i = Number(b);
ready

Revisions

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