Lukas Eder from JOOQL posts some code to benchmark SQL statement. Comes in flavours of PostgreSQL, Oracle and SQL-Server. Handy.
How to Benchmark Alternative SQL Queries to Find the Fastest Query
Tuning SQL isn’t always easy, and it takes a lot of practice to recognise how any given query can be optimised. One of the most important slides of my SQL training is the one summarising "how to be fast"