How do I measure the execution time of JavaScript code with callbacks?

前端 未结 10 1507
臣服心动
臣服心动 2020-11-30 16:28

I have a piece of JavaScript code that I am executing using the node.js interpreter.

for(var i = 1; i <         


        
10条回答
  •  误落风尘
    2020-11-30 16:37

    Use the Node.js console.time() and console.timeEnd():

    var i;
    console.time("dbsave");
    
    for(i = 1; i < LIMIT; i++){
        db.users.save({id : i, name : "MongoUser [" + i + "]"}, end);
    }
    
    end = function(err, saved) {
        console.log(( err || !saved )?"Error":"Saved");
        if(--i === 1){console.timeEnd("dbsave");}
    };
    

提交回复
热议问题