var startTime = newDate().getTime() //获得开始时间 var db = connect('log') for (let i = 0; i < 1000; i++) { db.test.insert({ num: 1 }) } var runTime = newDate().getTime() - startTime //获得运行时间 print('runTime is ' + runTime + 'ms') //runTime is 745ms
批量插入
1 2 3 4 5 6 7 8 9
var startTime = newDate().getTime() //获得开始时间 var db = connect('log') var tempArr = [] for (let i = 0; i < 1000; i++) { tempArr.push({ num: 1 }) } db.test.insert(tempArr) var runTime = newDate().getTime() - startTime print('runTime is ' + runTime + 'ms') // runTime is 48ms