-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
switchObj
performance
#13
Comments
Worth noting: For my particular use case (fast parsers) I assume that the functionality triggered by the switch case is inlined and not achieved by calling another function. That should obviously give an advantage to the switch approach as there is no need to call a function, but if JS engines optimized the switch object approach I'd love to use it. |
The pattern I'm promoting should be used in cases where you always know that the "case" argument will be "one of these properties" to get full benefit over blacklisted Note: I'm also interested in finding the best and most performance approaches, so this conversation is a definitely a good starting point. |
❤️ |
I also ran some tests with a switch object that is only setup once, I saw similar numbers.
+1 |
That’s what I tested as well: http://jsperf.com/switch-vs-object-literal-vs-module/2 The
+9001 |
This is really interesting - looking back on my original tests, they still show |
I've updated the section to reflect new information regarding the performance of |
It is a little hard to understand |
I absolutely love the elegance and reusability of the
switchObj
pattern (even if it’s slower), but I’d like to get this straight.See http://twatlr.com/thread/140407213511544833
Here’s @felixge’s test case: http://jsperf.com/object-vs-regular-switch
For my Velocity preso I created this test: http://jsperf.com/switch-vs-object-literal-vs-module/2 But it seemed regular
switch
was still faster. Any idea what’s up with that?Rick’s test case only seems to test for the case where
foo
is a defined key in theswitchObj
, and doesn’t have thehasOwnProperty
check. Perhaps that’s what caused the confusion?/cc @rwldrn @jdalton @felixge
The text was updated successfully, but these errors were encountered: