I am trying to write script that will measure execution time for query. For now I have script that I will include at the end of the question, but it seems that she collects results, add result on previous etc. So I wanted to ask you, do you maybe now how can I avoid that, where do I make a mistake?
var mysql = require('mysql');
var client = mysql.createConnection({
user: 'root',
password: '',
database: 'kong_centar'
//debug: true
});
var ignore = [mysql.ERROR_DB_CREATE_EXISTS,
mysql.ERROR_TABLE_EXISTS_ERROR];
client.on('error', function (err) {
if (ignore.indexOf(err.number) + 1) { return; }
throw err;
});
for(i=0; i<10; i++){
var pre_query = new Date().getTime();
client.query('select * from korisnik', function(err, result, fields){
var post_query = new Date().getTime();
var duration = (post_query - pre_query) / 1000;
console.log(duration);
if (err)
{
throw err;
}
else
{
//console.log(result);
for (var i in result)
{
//var people = result[i];
//console.log(people.firstname + ' ' + people.lastname);
}
}
});
}
client.end();