What is the difference in performance of making a single database (MySql) call that retrieves 10 results versus making 10 single db calls to retrieve those results individually?
If one is better than the other, is there a way I can go about to test the performance between the two? (I'm just curious because in the future if I have another question on performance, I could use the suggested way to test it out myself)
A single call will always be faster than several calls for the same data. Simply the network turn around and latency alone is a component, but also the start up and tear down of the SQL processing will have some impact.
What is heavier - a pound of apples or a bike?
Queries aren't equal. You cannot just compare them by numbers.
A query must be sensible in the first place. Doing its job the best way possible, not being imaginably "faster". That's the only reason to prefer one query to another.
I hope you meant different queries, not just a single query called 10 times.
Of course, running the same query multiple times should be avoided, as any other repetitive action - that's one of the basic rules in the art of programming.
And once your query/queries are right, you got to make them fast. And to answer the question how to do that - learn about profiling.
BENCHMARK <query>
and EXPLAIN <query>
are the tools for mysql profiling and performance tuning
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With