3 ms·
It's not even testing prefixes, it's testing the whole string. It's the equivalent of: process.env.OSTYPE === 'cygwin' || process.env.OSTYPE === 'msys' T
by ChrisSD 7y ago
It's not even testing prefixes, it's testing the whole string. It's the equivalent of:
process.env.OSTYPE === 'cygwin' || process.env.OSTYPE === 'msys'
Though I don't know enough about V8 to say how each is optimised.
- OskarS 7y agoOh, you're right! I missed the dollar sign! That makes it even worse! Unless V8 converts the regex to that expression (which it could maybe do, but I doubt), there's no way the regex version could be anything like as fast. Your version has the added benefit of also being far more readable and totally without any kind of memory allocation. Extraordinary package, this.
- Raphmedia 7y agoHere, test it. If you test it multiple time you get slightly different results. Both seem to be similar. You would have to ask the author why they went with the regex solution to know why they chose that one. Knowing Javascript, there's probably a pitfall we are not thinking about. http://jsben.ch/uFK8t http://jsben.ch/uFK8t