Operator vs function

Benchmark created on


Preparation HTML


Setup

const str = (input) => {
  switch (typeof input) {
    case 'string':
      return input
    case 'number':
    case 'boolean':
      return `${input}`
    default: return ''
  }
}

const someText = 'text'
const someUndefined = undefined
const someNull = null
const someBoolean = true
const someNumber = 123

Test runner

Ready to run.

Testing in
TestOps/sec
Operators
someText || ''
someUndefined || ''
someNull || ''
String(someBoolean)
String(someNumber)

ready
Function
str(someText)
str(someUndefined)
str(someNull)
str(someBoolean)
str(someNumber)
ready

Revisions

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