且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

NodeJS MySQL:衡量查询执行时间

更新时间:2021-10-05 23:30:17

一种选择是在查询之前进行时间戳记,在查询之后进行时间戳记,然后检查差异,如下所示:

One option is just to timestamp before the query and timestamp after the query and check the difference like this:

// get a timestamp before running the query
var pre_query = new Date().getTime();
// run the job
connection.query(query, function(err, rows, fields) {
  // get a timestamp after running the query
  var post_query = new Date().getTime();
  // calculate the duration in seconds
  var duration = (post_query - pre_query) / 1000;
});