Not much to say,Please see the code examples below

There is a summing function as follows,We need to know how long this function takes to execute

function add () {
 var sum=0;
 for (var i=0;i<1000000;i ++) {
  sum +=i;
return sum;

Define a test function,Pass the function under test as a parameter

function test (func) {
 var start=new date (). gettime ();//start time
 func ();//Execute the function under test
 var end=new date (). gettime ();//Accept time
 return (end-start) + "ms";//Return function execution takes time

Test and see actual execution time

var time=test (add);
console.log (time);
  • Previous How to retrieve the serial number of the SQL Server instance after installation
  • Next Detailed explanation of the method of using array names as function parameters in C ++ programming