SQLite VS MySQL

Hi guys,

Lately, I read in http://www.sqlite.org/speed.html, that sqlite is a bit faster than mysql and postgreSQL. But, when I perform a little testing to compare them in PHP, I got a contrast result.

For both testing, I use this table :
CREATE TABLE test (a varchar(20) PRIMARY KEY, b varchar(20), c varchar(20), d varchar(20), e varchar(20), f varchar(20), g varchar(20), h varchar(20), i varchar(20), j varchar(20))

for that table, I perform 5000 insert for both sqlite and mysql :
here’s for sqlite code :
=============== sqlite-test.php ===============

$time_start = microtime(true);
$db = sqlite_open(‘pegawai.db’, 0666, $sqliteerror);

sqlite_exec($db, “PRAGMA synchronous = OFF;”);
for($i = 0; $i < 5000; $i++)
{
$sql = “INSERT INTO test VALUES (‘a$i’,’b$i’,’c$i’,’d$i’,’e$i’,’b$i’,’b$i’,’b$i’,’b$i’,’b$i’)”;
$q = sqlite_query($db, $sql);
}
sqlite_close($db);
$time_end = microtime(true);
$time = $time_end – $time_start;
echo “executed in $time seconds\n”;

=========================================

and here’s for mysql code :
============= mysql-test.php ================

………….
$time_start = microtime(true);
for($i = 0; $i < 5000; $i++)
{
$sql = “INSERT INTO test VALUES (‘a$i’,’b$i’,’c$i’,’d$i’,’e$i’,’b$i’,’b$i’,’b$i’,’b$i’,’b$i’)”;
$q = mysql_query($sql);
}
$time_end = microtime(true);
$time = $time_end – $time_start;
echo “executed in $time seconds\n”;
…………..

===========================================

when I run those 2 script, the first one (sqlite) run for 43.4918169975 seconds, while the second (mysql) only take 0.52137298584 seconds.

It means that sqlite run 80x longer than mysql did (very contrast with the one I read in http://www.sqlite.org/speed.html).

Please tell me where do I did wrong. Thanks very much.

About resariski

me - Resa - a girl who was born at December 16th is the youngest daughter (from 4 brothers) in my family. This is my official weblog. View all posts by resariski

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: