Satish Ravipati
Satish Ravipati

Reputation: 1449

performance on iterations in PHP

Can someone tell me about this performance issue

I've got 2 arrays, I need to pick 5 numbers from these 2 arrays and work on the logic

the first array has got 5 number, out of which I need to pick 3 numbers and the second array has got 4 numbers, out of which I need to pick 2 number

so taking this into consideration 5c3 - 10 and 4c2 - 6 which means 60 iterations for a single case

Is the method I'm approaching the right way?? is there any performance issue on this type of iterations ??

Upvotes: 1

Views: 67

Answers (1)

Danilo Radenovic
Danilo Radenovic

Reputation: 1029

If you have to go through the whole array and pick numbers, then there is no optimization for that. The execution time depends on the size of arrays, meaning the bigger the size - higher execution time.

Although, if you know that it will always be exactly 5 numbers from two rows whose elements will not change, than I think you could generate all the possible valid combinations, store them in a database or file, and return a random one (if random choice is what you are looking for). In this case, you will achieve some optimization.

Upvotes: 1

Related Questions