chuanxshi / javascript-patterns

JavaScript Design Patterns

Home Page:http://shichuan.github.io/javascript-patterns

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

When this conditional expression can be better than anything else?

chiefGui opened this issue · comments

Hello guys.

In this conditional pattern doc, you say:

Using the normal pattern will generally outperform the regex (alternative method 1) in a loop, [...]"

Then I made a little test – still doubtful, but can give us an idea: Conditional Expressions Difference.

I really was expecting that regex would be faster/better outside a loop – as I outputted on the alert() – but it doesn't seem to happen.

Yes, I know – jsPerf isn't the most trustful way of performance rating, but as I said, it can give us a starting point.

So, what does "outperform" really means?