I'm playing with 3 types of data to be inserted in a list. I'm wondering which is faster. Should I create 3 different lists or should I create an object list which have 3 variables in it?
-
It doesn't matter. This kind of micro-optimization is meaningless for performance. You should write the code so it reads as clearly and uses the best object encapsulation practices as possible.duffymo– duffymo2014-03-28 13:19:27 +00:00Commented Mar 28, 2014 at 13:19
-
1i think the 2nd option is better. tomorrow you want to play with 4th or 5th data do want to end up creating 2 more lists or just create 2 variables inside the object and values 2 these objects. mind tickling rightvikeng21– vikeng212014-03-28 13:26:08 +00:00Commented Mar 28, 2014 at 13:26
2 Answers
It doesn't matter. This kind of micro-optimization is meaningless for performance.
You should write the code so it reads clearly and uses the best object encapsulation practices possible.
I would vote for better encapsulation - if those three disparate data types belong together, it's usually best to make that clear by encapsulating them in a single object so you can manage their state together.
Comments
It would depend on what you want from it - if they are directly related and you only use the 3 data types together then , stick them in an object and create getters/setters for them.
If you need to access them independently then 3 separate lists may be better.
Before considering speed you should consider the functionality - there is no point storing 3 completely unrelated data types together.