SQLite vs. INI: Read, Write, and Read/Write/ReadThis test consists of three tests measuring the speed of SQLite's and INI files' read speeds, write speeds, and read/write/read speeds.
ReadTest consists of reading 1,000 records, printing the value of each record as it's read.
INI:
1 = a 2 = a 3 = a{...}
| SQLite:
one | two ----|---- 1 | a 2 | a 3 | a{...}
|
WriteConsists of writing 1,000 records in the same format as above.
Read/Write/ReadReads each of the 1,000 records, prints the value of the record, overwrites it with "b", and prints the new value. (SQLite transactions are not used as it is a single query, and not a group)
ReadSQLite | INI |
|
|
function onScriptLoad() { LoadModule( "sq_lite" ); local i, checkpoint, sql; checkpoint = GetTickCount(); sql = ConnectSQL( "a.sql" ); for( i = 1; i <= 1000; i++ ) { local res = QuerySQL( sql, "SELECT two FROM a WHERE one = " + i ); print( i + " = " + GetSQLColumnData( res, 0 ) ); FreeSQLQuery( res ); } local timeTaken = GetTickCount() - checkpoint; print( timeTaken + " ticks." ); } | function onScriptLoad() { LoadModule( "sq_ini" ); local i, checkpoint; checkpoint = GetTickCount(); for( i = 1; i <= 1000; i++ ) print( i + " = " + ReadIniString( "a.ini", "a", i.tostring() ) ); local timeTaken = GetTickCount() - checkpoint; print( timeTaken + " ticks." ); } |
|
|
Time: 1,514 ticks | Time: 6,892 ticks |
WriteSQLite | INI |
|
|
function onScriptLoad() { LoadModule( "sq_lite" ); local i, checkpoint, sql; checkpoint = GetTickCount(); sql = ConnectSQL( "a.sql" ); QuerySQL( sql, "CREATE TABLE a ( one INTEGER, two TEXT )" ); QuerySQL( sql, "BEGIN TRANSACTION" ); for( i = 1; i <= 1000; i++ ) { QuerySQL( sql, "INSERT INTO a VALUES ( " + i + ", 'a' )" ); } QuerySQL( sql, "END TRANSACTION" ); local timeTaken = GetTickCount() - checkpoint; print( timeTaken + " ticks." ); } | function onScriptLoad() { LoadModule( "sq_ini" ); local i, checkpoint; checkpoint = GetTickCount(); for( i = 1; i <= 1000; i++ ) WriteIniString( "a.ini", "a", i.tostring(), "a" ); local timeTaken = GetTickCount() - checkpoint; print( timeTaken + " ticks." ); } |
|
|
Time: 287 ticks | Time: 11,481 ticks |
Read/Write/ReadSQLite | INI |
|
|
function onScriptLoad() { LoadModule( "sq_lite" ); local i, checkpoint, sql; checkpoint = GetTickCount(); sql = ConnectSQL( "a.sql" ); for( i = 1; i <= 1000; i++ ) { local res = QuerySQL( sql, "SELECT two FROM a WHERE one = " + i ); print( i + " = " + GetSQLColumnData( res, 0 ) ); FreeSQLQuery( res ); QuerySQL( sql, "UPDATE a SET two = 'b' WHERE a = " + i ); res = QuerySQL( sql, "SELECT two FROM a WHERE one = " + i ); print( i + " = " + GetSQLColumnData( res, 0 ) ); FreeSQLQuery( res ); } local timeTaken = GetTickCount() - checkpoint; print( timeTaken + " ticks." ); } | function onScriptLoad() { LoadModule( "sq_ini" ); local i, checkpoint; checkpoint = GetTickCount(); for( i = 1; i <= 1000; i++ ) { print( i + " = " + ReadIniString( "a.ini", "a", i.tostring() ) ); WriteIniString( "a.ini", "a", i.tostring(), "b" ); print( i + " = " + ReadIniString( "a.ini", "a", i.tostring() ) ); } local timeTaken = GetTickCount() - checkpoint; print( timeTaken + " ticks." ); } |
|
|
Time: 264,316 ticks | Time: 29,800 ticks |
ConclusionSQLite is excellent for reading and writing long chains of data or single pieces of data, but fails when expected to write without using transactions. INIs are slower when reading and writing long chains of data, but performed better than SQLite when expected to read, write, and read again.
Because transactions could not have been used, the performance of SQLite was hindered by that and because SQLite had to check the integrity of each entry as it was written. INIs are efficient for that purpose, but because of how specific the situation was, I'm concluding that
SQLite is better than using INIs in overall performance, and can perform even faster if I/O synchronization was disabled (which can corrupt data if power is lost or the server crashes).