11

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 ?

I took performance statistics for Android SQLite.

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

Flat file have less time rather than SQLite

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

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

Please suggest me some things how to improve these statistics.

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 

Thanks

4

1 回答 1

17

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.

Take a look at 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();
}
于 2012-10-09T08:54:26.017 回答