javascript - why js can Improved code efficiency use function? -
when use mongodb in js,i found code's efficiency different between example1(122ms) , example2(390ms),example1 put code in function() example2 not. why?
example1:
var timepage2 = function(){ var start = (new date()).gettime(); var page1; for(var i= 0; < 10000; i++){ page1 = db.test.find({"n":{"$gt":i*100}}).limit(100); } var end = (new date()).gettime(); var timediff = end - start; print("update took2:" + timediff+"ms"); } timepage2()
example2:
//var timepage2 = function(){ var start = (new date()).gettime(); var page1; for(var i= 0; < 10000; i++){ page1 = db.test.find({"n":{"$gt":i*100}}).limit(100); } var end = (new date()).gettime(); var timediff = end - start; print("update took2:" + timediff+"ms"); // } // timepage2()
Comments
Post a Comment