jonschlinkert / kind-of

Get the native JavaScript type of a value, fast. Used by superstruct, micromatch and many others!
https://github.com/jonschlnkert
MIT License
351 stars 40 forks source link

Consider switch-case for further optimization #16

Closed rajivramv closed 7 years ago

rajivramv commented 7 years ago

Consider replacing the if-else lines below this to switch case? https://github.com/jonschlinkert/kind-of/blob/72d2f2bfcd3c0f3306305cde147facf63a3c0e7e/index.js#L52

jonschlinkert commented 7 years ago

We've had this discussion in the past, but I use benchmarks to determine what format to use.

fwiw, I've had other variations of kind-of using switch statements in the benchmarks, and there were situations where it was minutely faster, but as the code is currently switch statements were a tiny bit slower.

I don't have an emotional attachment to if/else statements, switch statements, or any other kind of code, I just use whatever appears to be the most performant, and I usually re-run the benchmarks and try new configurations with each new node.js release.