When I’m poking at a SQLite file and add an index or rewrite a query, I want a number, not a feeling that it got faster. The sqlite3 command-line shell has a built-in stopwatch for that.
Type this at the sqlite> prompt:
.timer on
From then on, every statement prints a timing line after its result, something like this:
sqlite> SELECT count(*) FROM events WHERE kind = 'login';
18342
Run Time: real 0.041 user 0.030118 sys 0.010203
real is the wall-clock time in seconds, which is the one you’ll usually compare. user and sys are the CPU time spent in SQLite itself and in the operating system (mostly reading the file). A big gap between real and the other two often means the query was waiting on the disk. Turn it off again with .timer off.
The handy pattern is before and after: time the query, create the index, run the same query again. Pair it with EXPLAIN QUERY PLAN when you want to know why it changed. If you always want timings, put .timer on in ~/.sqliterc, a file the shell reads at startup.
The caveat is caching. The first run reads pages from disk and later runs often get them from the operating system’s cache, so the second run looks faster even when you changed nothing. Run each version a few times and compare the later runs, not the very first one. And these are times inside the shell on your machine: an app that talks to the same database file through a library and over a slower disk can see very different numbers.
Further reading: SQLite: Command Line Shell For SQLite, SQLite: EXPLAIN QUERY PLAN