I have a MVVM Xaml application and I am trying to squeeze every last millisecond out of the startup out of this that I can. One thing that I noticed is that there is a conversion from codes to strings that is being pulled from the App.Config. There are only 5 values, so not a lot. I thought, I could put this in a switch statement and it would be faster (To my surprise it was the same time). This is called multiple times, around 80 and can be any one of the 5 values or none of the 5. Previously there was just a string.IsNullOrEmpty check on the value from ConfigurationManager.AppSettings to see if it found a value. In my switch I just put a default return “”. These values will rarely change, if ever, but could potentially have more.
So my question, is there a performance benefit to using switch or App.Config as the number of items changes? The only reason I put anything in App.Config is if the user needed to modify something without rebuilding the application. Currently since my testing shows the time to be the same I would tend to keep this in the App.Config, but I would just like to hear everyone’s thought on it.
Thanks,
TJ
Your parameters in the App config are cached after the first time they are read. The initial read will probably require some overhead since it costs disk access.
The switch will also be faster in this case, we’re talking nanoseconds.
I’d imagine that once your config values are actually read in the first time, the performance of reading them from the cache is similar.
Since it seems you have a reason for allowing them to be changed by the user, I’d leave them in the app.config.