0

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?

2
  • 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. Commented Mar 28, 2014 at 13:19
  • 1
    i 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 right Commented Mar 28, 2014 at 13:26

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.