Nisha Patel
Problem
I have a simple Nodejs program to test query performance but I have this issue where I have an array of queries and when I loop over them and measure their timings, the second one is always faster than the first one, like let's say I have queries A and B, if the array looks like this [A, B], B is gonna be faster, but if I changed the order to [B, A], A is gonna be faster, but running them individually ( like having a list of just A or B ) or in psql I found that they both almost have identical results. Here is the code.
index.js
queryPref.js
as you can see I'm trying to initiate a new client for each query, but it seems like it's doing nothing.
I've tried using connection Pool instead of a client, yet got the same results (the second one is always faster ). I've also tried measuring the average over 1000 queries with client and pool but gave the same result again.
Solution
We could simply calculate like below inside your for loop, const startTime = Date.now(); const timeTaken = Date.now() - startTime;
and add the timeTaken in the common variable outside of your for loop.
Answered by: >Jeyaprakash Ayyanan
Credit: >StackOverflow
Blog Links:
>How to manage the Text in the container in Django?
>Fix webapp stops working issue in Django- Python webapp
>Creating a form in Django to upload a picture from the website
>Sending Audio file from Django to Vue
>How to keep all query parameters intact when changing page in Django?
>Solved: TaskList View in Django
>Implement nested serializers in the Django rest framework
>How to filter events by month in Django?
>Sorting the restframework in Django
>Ways to access instances of models in view in order to save both forms at once in Django
>What makes index.html have such kind of name in Django?
>Fix Module Not Found during Deployment- Django
>Creating a Django with existing directories, files, etc.?
>How to Read a CSV file with PHP using cURL?