Get Query execution time SDK 2.5


I am working on my thesis for my academic degree, and I need to know the accurate execution time of a query.
I see this information in the workbench, but I want to iterate a lot of query for save their runtimes in ms in a .csv file.
The Stopwatch gives me inaccurate results, because a simple SELECT query’s elapsed time is 30-50ms, but the StopWatch’s EllapsedMillisenconds value is 100-140ms.
This is my code snippet, I guess I am using a good method.

var bucket = cb.OpenBucket(“travel-sample”);
string qq = “SELECT country FROM travel-sample WHERE name=“Texas Wings”;”;

             run_Time.Start(); //StopWatch
             var result = bucket.Query<dynamic>(qq);

Is there a command in .NET SDK 2.5 for get the queries execution time?

Thank you in advance!

Did you check result.Metrics


Oh my god, how blind I am! :zipper_mouth_face:
Thanks for your fast and helpful response!


Just to make sure you’re looking at the right data for your thesis:

  • result.Metrics will have the query execution time within Couchbase Server
  • The stopwatch will have total execution time relative to the client, including network latency from the client to the query node as well as the time it takes to deserialize the resulting JSON to an object graph

Also, if full end-to-end time relative to your client is your goal, I suspect performance will improve if you use a POCO instead of “dynamic”. If result.Metrics is what you need then it shouldn’t matter.


1 Like