I am currently trying to update the SQLite version in our software from version 1.0.74
to the most recent 1.0.113
(As on 7th December).
I tried some of our most used scenarios in a console application with both the versions.
public class SQLitePerformance {
public static void Main(string[] args) {
try {
var dataSource = @"C:\views\SpikeSqlite.db";
var conString =
$"Data Source = {dataSource};Journal Mode = wal;Pooling = true;Max Pool Size = 100;foreign keys = true";
// Loading SQLite once for warm-up.
GetSqliteVersionLoaded(conString);
var watch = Stopwatch.StartNew();
for (int i = 0; i < 1000; i++) {
var connection = new SQLiteConnection(conString);
connection.Open();
}
Console.WriteLine($"Opening 1000 connections took : {watch.ElapsedMilliseconds}ms");
} catch (Exception e) {
Console.WriteLine(e);
}
}
public static void GetSqliteVersionLoaded(string connectionString) {
using (var connection = new SQLiteConnection(connectionString)) {
connection.Open();
using (var cmd = connection.CreateCommand()) {
cmd.CommandText = "select sqlite_version();";
var version = cmd.ExecuteScalar().ToString();
Console.WriteLine("SQLite version : " + version);
}
connection.Close();
}
}
}
When I compiled this code with both the versions, here's the result I got :
SQLite version : 3.7.7.1 Opening 1000 connections took : 580ms Press any key to continue . . .
SQLite version : 3.32.1 Opening 1000 connections took : 669ms THE END. Press any key to continue . . .
It's clearly slower than the older version. I know SQLite is not all about opening connections, but an open connection is necessary to perform any operation. It is fair to include this time taken to open a connection in the actual scenario like an INSERT
or UPDATE
of a row.