Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to optimize Sqlite data query performance in Android

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

In this issue, the editor will bring you about how to optimize the performance of Sqlite data query in Android. The article is rich in content and analyzed and described from a professional point of view. I hope you can get something after reading this article.

(1) compile SQL statements (use SQLiteStatement for repeated insert operations)

(2) showing the use of transactions (things can increase the speed of about 8 bits when doing database update and modification operations) (3) setting up indexes (which I don't think is necessary, indexes are helpful when querying all databases) (4) query data optimization (use less cursor.getColumnIndex, this is the test we are talking about today) (5) capacity adjustment of ContentValues (the initial capacity of ContentValues is 8. If the added data exceeds 8, a double expansion operation will be carried out, so it is recommended to estimate the content filled in ContentValues) (6) close Cursor in time (there is nothing to say, you should get into the habit of writing code) (7) time-consuming asynchronization (asynchronous processing is best used for large data operations)

About the test of cursor.getColumnIndex

Today we are going to test the speed of getColumnIndex.

Query a piece of data

The picture above shows the original data of querying a piece of information in your program. After the test, the output time is 43 milliseconds.

Then we write a new method to define the front of the display column, and then directly take the sequence number of the column.

Then I called it with the new method, and when I saw the result, I tested it twice, which was 42 and 43, that is to say, there was basically no change.

Query multiple pieces of data (around 2W6)

This time, let's find another way to get all the information. There is an amount of 2W6 data in the local Sqlite database. Let's take a look at the code that uses getcolumnindex.

Then we execute and see that the usage time is 11366.

Next, let's write a method to remove getcolumnindex.

After the implementation of this time is 11168, compared with the original can save some, or some help.

The above is how to optimize the performance of Sqlite data query in Android shared by Xiaobian. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report