April 18, 2024, 07:17:32 pm

Author Topic: [Benchmark] SQLite vs INI  (Read 1987 times)

0 Members and 1 Guest are viewing this topic.

stormeus

  • Vice Underdog
  • Crazy Man
  • *
  • *
  • Posts: 1755
  • Country: us
  • VC:MP Developer
    • View Profile
    • GTA VICE CITY Respective owner
[Benchmark] SQLite vs INI
« on: November 23, 2011, 10:07:08 pm »
SQLite vs. INI: Read, Write, and Read/Write/Read
This test consists of three tests measuring the speed of SQLite's and INI files' read speeds, write speeds, and read/write/read speeds.

Read
Test consists of reading 1,000 records, printing the value of each record as it's read.
INI:
Quote
1 = a
2 = a
3 = a{...}


SQLite:
Quote
one | two
----|----
1   | a
2   | a
3   | a{...}

Write
Consists of writing 1,000 records in the same format as above.

Read/Write/Read
Reads 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)

Read
SQLite
INI


Quote
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." );
}
Quote
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 ticksTime: 6,892 ticks

Write
SQLite
INI


Quote
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." );
}
Quote
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 ticksTime: 11,481 ticks

Read/Write/Read
SQLite
INI


Quote
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." );
}
Quote
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 ticksTime: 29,800 ticks

Conclusion
SQLite 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).
Agree Disagree Funny Winner Pwnt Informative Friendly Useful Optimistic Artistic Late Brain Donor

<krystianoo> stormeus do good job
<krystianoo> with recent update
<krystianoo> if not agree; jeb yourself in head
<Avenger> yesterday you said death to stormeus
<karan> double standard krystianoo
<karan> he called him fake prophet too
<krystianoo> sure fake prophet
<krystianoo> but with recent updates real

Thijn

  • Forum Administrator
  • Crazy Man
  • *
  • *
  • *
  • Posts: 2946
  • Country: nl
    • View Profile
Re: [Benchmark] SQLite vs INI
« Reply #1 on: November 24, 2011, 02:31:40 pm »
Even though INI's relay on the I/O speed of the OS/HDD its overall slower then Sqlite.
And even slower if its a big file.
Also, One sqlite database with around 5700 accounts, with each stats and aliases. is 1.7 MB.
If you have to convert that to INI's you'll need a bit more space.
Agree Disagree Funny Winner Pwnt Informative Friendly Useful Optimistic Artistic Late Brain Donor

I'm not totally useless,
I can be used as an bad example ;)

"Never do Today, What you can do Tomorrow"


Skirmant

  • Vice Underdog
  • Crazy Man
  • *
  • *
  • Posts: 681
  • Country: il
  • Ignorance is bliss.
    • View Profile
Re: [Benchmark] SQLite vs INI
« Reply #2 on: November 27, 2011, 06:07:04 pm »
Even though INI's relay on the I/O speed of the OS/HDD its overall slower then Sqlite.
And even slower if its a big file.
Also, One sqlite database with around 5700 accounts, with each stats and aliases. is 1.7 MB.
If you have to convert that to INI's you'll need a bit more space.

I know, right? But no worries, I'm fighting the good fight and proving that INI is faster on...
http://vcmp.liberty-unleashed.co.uk/forum/index.php?topic=488.0 :3
Read - down. Write to go.
« Last Edit: November 27, 2011, 06:10:04 pm by Skirmant »
Agree Disagree Funny Winner Pwnt Informative Friendly Useful Optimistic Artistic Late Brain Donor

"C++ is a horrible language" - Linus Torvalds, creator of Linux

Quote
<SLC> nope. changed my mind. squirrel still sux dix
<SLC> it's just a piece of sh!t
* SLC has quit (Connection closed)

stormeus

  • Vice Underdog
  • Crazy Man
  • *
  • *
  • Posts: 1755
  • Country: us
  • VC:MP Developer
    • View Profile
    • GTA VICE CITY Respective owner
Re: [Benchmark] SQLite vs INI
« Reply #3 on: November 27, 2011, 07:36:12 pm »
Quote from: stormeus
If it's 20x faster, SQLite still outperforms it.
Agree Disagree Funny Winner Pwnt Informative Friendly Useful Optimistic Artistic Late Brain Donor

<krystianoo> stormeus do good job
<krystianoo> with recent update
<krystianoo> if not agree; jeb yourself in head
<Avenger> yesterday you said death to stormeus
<karan> double standard krystianoo
<karan> he called him fake prophet too
<krystianoo> sure fake prophet
<krystianoo> but with recent updates real