Possible Duplicate:
SQL Server CE 4.0 performance comparison
I am evaluating whether to use SQL Server CE 4 or SQLite as local cache for a desktop app. I ran a simple test to see how they will fare under pressure, since speed is very important to the app. The test consisted of dumping random data into the table below and then querying it - loop 500 times.
CREATE TABLE [Lines] (
[KeyHash] NVARCHAR(4000) NOT NULL,
[Method] NVARCHAR(100) NOT NULL,
[Value] TEXT NOT NULL,
[AddedOn] TIMESTAMP DEFAULT CURRENT_TIMESTAMP NULL,
Primary Key ([KeyHash], [Method])
)
The code to insert data was fairly simple.
using (var conn = GetConnection()) {
using (var cmd = conn.CreateCommand()) {
cmd.CommandText = "INSERT INTO Lines(KeyHash, Method, Value) VALUES (@KeyHash, @Method, @Value)";
PopulateWithRandom(cmd);
cmd.ExecuteNonQuery();
}
}
The code to query data was fairly simple too.
using (var conn = GetConnection()) {
using (var cmd = conn.CreateCommand()) {
cmd.CommandText = "SELECT Value FROM Lines WHERE KeyHash=@KeyHash AND Method=@Method";
cmd.Parameters.AddWithValue("@KeyHash", key);
cmd.Parameters.AddWithValue("@Method", method);
return (string) cmd.ExecuteScalar();
}
}
The results were kind of crazy. SQL Server CE finished in 18 seconds, while SQLite completed everything in 4.7 seconds.
Am I missing something simple or is SQLite just that much faster?
P.S. Full results:
SQL Server CE 4
Total: 18032 milliseconds
Insert: 10069 milliseconds
Query: 6940 milliseconds
SQLite
Total: 4739 milliseconds
Insert: 3248 milliseconds
Query: 496 milliseconds
I should not that I open and close the connection (e.g. using the using
construct) on every operation.