Number('0b' + s) vs parseInt(s, 2) for parsing binary

Benchmark created on


Setup

const s1 = '0';
const s2 = '1';
const s3 = '000000000000000000000000000000000000';
const s4 = '111111111111111111111111111111111111';
const s5 = '100000000000000000000000000000000000';
const s6 = '011111111111111111111111111111111111';
const s7 = '101010101010101010101010101010101010';

Test runner

Ready to run.

Testing in
TestOps/sec
Number('0b' + s)
Number('0b' + s1);
Number('0b' + s2);
Number('0b' + s3);
Number('0b' + s4);
Number('0b' + s5);
Number('0b' + s6);
Number('0b' + s7);
ready
parseInt(s, 2)
parseInt(s1, 2);
parseInt(s2, 2);
parseInt(s3, 2);
parseInt(s4, 2);
parseInt(s5, 2);
parseInt(s6, 2);
parseInt(s7, 2);
ready

Revisions

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