I am currently using syntax to generate my form elements, and all the content on start up. I was wondering if there is any performance gain from this? I just don’t like the bloated feeling of using the editor in the source.
I mean, basicly if I were to use the editor I’d have this setup for my project: 3 panels x 44 icon images and text elements.
Where as in my code I can just use a loop to generate all the elements since theres not a whole lot of differences in the propertys except source or value.
No, there is no advantage to what you’re doing. In fact, in a small way, what you’re doing is less performant.
For example, consider you have ten text boxes on your form, each with the text “1” through “10” in them. Your form’s designer code would look something like this:
(Actually, it would be broken up, since the instantiation, initialization, and addition are usually in different spots, but this is fine for illustration purposes).
Now, granted, this is verbose. But pure verbosity in generated code generally doesn’t matter since nobody is writing (or, ideally, reading) it. Unless it hinders performance, of course, but I’m getting to that.
Using your approach, you’d (rightly) use a loop, since this code is quite repetitive and just begging to look a little more concise. Something like…
Certainly much more readable. But, however, let’s look at the work that the runtime actually has to do for each text box in each approach.
In the first, it does this:
TextBoxTextproperty to a string literalControlscollectionIn the second, it has to do this:
TextBoxTextpropertyControlscollectionNow, is the additional work substantial? No. Will you ever notice the ever-so-slight performance hit you take from the additional work? If you do, you need a new computer. But your question was whether or not your approach had better performance, and the answer is “no”.