Sobes.tech
Junior — Middle

How can query performance be measured?

sobes.tech AI

Answer from AI

To measure query performance in Java, several approaches can be used:

  • Measuring execution time with System.currentTimeMillis() or System.nanoTime():
long start = System.nanoTime();
// execute query
long end = System.nanoTime();
long duration = end - start; // time in nanoseconds
  • Using profilers and monitoring tools, such as JProfiler, VisualVM.
  • In web applications, filters or aspects can be used for automatic measurement of query execution time.

Thus, a simple method is to record the start and end times of the query execution and calculate the difference.

How can query performance be measured? — Java - sobes.tech