TIL NOTE #028
console.time Is the Fastest Profiler You Already Have
Something is slow. Your instinct is to fire up a profiler.
Start here instead:
console.time("database query");const result = await db.query(sql);console.timeEnd("database query");// Outputs: database query: 234.5msTakes 3 seconds to add. No setup. Instant feedback.
If the query is 234ms and the request is 2000ms, the database isn’t the problem. Keep digging.
Once you find the real bottleneck, then use clinic.js or Chrome DevTools to see the flame graph and optimize the exact lines.
80% of the time, console.time is enough. The 20% that needs deeper profiling is obvious once you measure.
Profile iteratively. Measure first, optimize second.