In my Android application I have to fill an arraylist object with the data taken from a database. Also the data should be sorted. So i have two ways.
out of these which is more efficient and less affecting the runtime. Need some help. Thank you!
Sort the data while taking from the database using SQL and put into array
If you are able to sort data on database level, do it. Sorting on database level is much more faster as in memory - especially if your memory is limitated in the case of many records. Also performance can be increased by an usage of indexes which provide many databases.
So if you can and are able to sort in database, sort in database. If not, sort in application but here you are limitated by memory and sorting is significantly slower.
Note: It's worth to mention that if your sorting algorithm is very changeble during runtime (with high frequency and begins changing after data are retrieved from database) it's good approach to think about sorting in application and not in database and make some analysis focused on advantages and disadvatages due to application requirements (performance for instance).
It depends on many things. But for general cases sorting from database is better as it may use indexings internally.
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