如何提高SQLite数据库Android的性能 [英] How to improve performance for SQLite database for android

查看:163
本文介绍了如何提高SQLite数据库Android的性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有相关的计算器这个话题几个问题,但我没有得到正确的答案。我对平面文件的性能有些疑惑,是更好地使用,而不是SQLite的纯文本文件?

There are few questions related to this topic on stackoverflow, But I didn't get the proper answer. I have some doubts on performance of flat files, Is it better to use flat files instead of SQLite ?

我把性能统计为Android 的SQLite

I took performance statistics for Android SQLite.

我有一个表,该表有21列的性能统计信息。

I have performance statistics for one table which have 21 columns

任何人都可以请建议如何减少这种插入时间。

Can anybody please suggest how to reduce this insertion time.

Records  Write time in ms   Read time in ms
1000      67813                   608
1000      66340                   604
1000      64359                   609
10000     679837                  5159
10000     618062                  5110
10000     644638                  5729
10000     646878                  5890

平面文件有时间,而不是 SQLite的少

所以有人请建议我如何可以改善这一次SQLite的。

So anybody please suggest me how can i improve this time for SQLite.

我使用简单的打开数据库插入使用ContentValues​​ 和数据库关闭。

I am using simple database open insert using ContentValues and database close.

请给我建议一些事情如何改进这些统计信息。

Please suggest me some things how to improve these statistics.

下面answer.Still使用我想提高这些性能后,更新的性能统计信息。

Updated Performance statistics after using below answer.Still i want to increase these performance.

Records    Writetime in ms         Readtime in ms   
1000        1645                       530          
1000        2497                       672          
1000        3143                       610          
10000       16356                     5243          
10000       14006                     5122          
10000       13158                     5002          
10000       14828                     5234          
100000      125525                    77622 

感谢

推荐答案

我相信你使用的是循环插入1000或10000。 使用事务,这将大大减少写入时间。我已经遇到过这样的问题,它从约30秒缩短写入时间在我的情况下大约不到1秒。

I believe you are inserting 1000 or 10000 using a loop. Use TRANSACTIONS , it will dramatically reduce the write time. I already encountered such an issue and it reduced the write time in my case from around 30 seconds to about less than 1 second.

看看<一href="http://www.android-app-market.com/sqlite-optimization-in-android-programming-sqlite-optimization-in-android-apps.html">this.

基本上,你应该做的是:

Basically, what you should do is :

db.beginTransaction();
try{
    for(int i = 0 ; i < LENGTH ; i++ ) {
        // execute SQL
    }
    db.setTransactionSuccessful(); // marks a commit
    }
finally{
    db.endTransaction();
}

这篇关于如何提高SQLite数据库Android的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆