(silent, docCount)
| 59 | |
| 60 | // scenario for many individual, consecutive inserts |
| 61 | function initializeDatabase(silent, docCount) { |
| 62 | var start, end, totalTime; |
| 63 | var totalTimes = []; |
| 64 | var totalMS = 0.0; |
| 65 | |
| 66 | if (typeof docCount === "undefined") { |
| 67 | docCount = 5000; |
| 68 | } |
| 69 | |
| 70 | arraySize = docCount; |
| 71 | |
| 72 | for (var idx = 0; idx < arraySize; idx++) { |
| 73 | var v1 = genRandomVal(); |
| 74 | var v2 = genRandomVal(); |
| 75 | |
| 76 | start = process.hrtime(); |
| 77 | samplecoll.insert({ |
| 78 | customId: idx, |
| 79 | val: v1, |
| 80 | val2: v2, |
| 81 | val3: "more data 1234567890" |
| 82 | }); |
| 83 | end = process.hrtime(start); |
| 84 | totalTimes.push(end); |
| 85 | } |
| 86 | |
| 87 | if (silent === true) { |
| 88 | return; |
| 89 | } |
| 90 | |
| 91 | for (var idx = 0; idx < totalTimes.length; idx++) { |
| 92 | totalMS += totalTimes[idx][0] * 1e3 + totalTimes[idx][1] / 1e6; |
| 93 | } |
| 94 | |
| 95 | // let's include final find which will probably punish lazy indexes more |
| 96 | start = process.hrtime(); |
| 97 | samplecoll.find({customIdx: 50}); |
| 98 | end = process.hrtime(start); |
| 99 | totalTimes.push(end); |
| 100 | |
| 101 | //var totalMS = end[0] * 1e3 + end[1]/1e6; |
| 102 | totalMS = totalMS.toFixed(2); |
| 103 | var rate = arraySize * 1000 / totalMS; |
| 104 | rate = rate.toFixed(2); |
| 105 | console.log("load (individual inserts) : " + totalMS + "ms (" + rate + ") ops/s (" + arraySize + " documents)"); |
| 106 | } |
| 107 | |
| 108 | // silent : if true we wont log timing info to console |
| 109 | // docCount : number of random documents to generate collection with |
no test coverage detected