Categories
Articles Benchmarks

“Appearances can be deceiving Mr. Anderson” – a.k.a. short code is not always fast code

Reading Time: 2 minutes

I used to take pride in my short, bulletproof and elegant String and Number type checks:

// Check whether obj is a Number
obj + 0 === obj

// Check whether obj is a String
obj + '' === obj

I always thought that apart from being short and elegant, they should be faster.

However, some quick tests gave me a cold slap in the face and proved my assertion to be entirely false.