简体   繁体   中英

Is it faster to count data client side or server side?

Say I have a html table of Cars with 1000 rows and I want to display the total number of cars that are a certain brand in a sidebar. Is it faster to use JavaScript and loop through the table rows, find number of cars the equal brand X , and then append that total in the sidebar or is it faster to just create a scope in my model like scope -> { where(brand = 'toyota' }.count

Databases are optimized for these kind of things. So your best move is to go with queries when possible. Plus is less error prone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM