Number(arg) vs typeof arg === 'number' ? arg : Number(arg)

Benchmark created on


Description

Check if Number(arg) is faster or slower than typeof arg === 'number' ? arg : Number(arg)

Setup

const arg = 123

window.result = 123

Test runner

Ready to run.

Testing in
TestOps/sec
Number(arg)
window.result = Number(arg)
ready
typeof arg === 'number'
window.result = typeof arg === 'number' ? arg : Number(arg)
ready

Revisions

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