MCPcopy Index your code
hub / github.com/techfort/LokiJS / perfFindInterlacedInserts

Function perfFindInterlacedInserts

benchmark/benchmark_binary.js:186–225  ·  view source on GitHub ↗
(multiplier)

Source from the content-addressed store, hash-verified

184
185// Find Interlaced Inserts -> insert 5000, for 5000 more iterations insert same test obj after
186function perfFindInterlacedInserts(multiplier) {
187 var start, end;
188 var totalTimes = [];
189 var totalMS = 0;
190
191 var loopIterations = arraySize;
192 if (typeof (multiplier) != "undefined") {
193 loopIterations = loopIterations * multiplier;
194 }
195
196 for (var idx = 0; idx < loopIterations; idx++) {
197 var customidx = Math.floor(Math.random() * arraySize) + 1;
198
199 start = process.hrtime();
200 var results = samplecoll.find({
201 'customId': customidx
202 });
203 // insert junk record, now (outside timing routine) to force index rebuild
204 var obj = samplecoll.insert({
205 customId: 999,
206 val: 999,
207 val2: 999,
208 val3: "more data 1234567890"
209 });
210
211 end = process.hrtime(start);
212 totalTimes.push(end);
213
214 }
215
216 for (var idx = 0; idx < totalTimes.length; idx++) {
217 totalMS += totalTimes[idx][0] * 1e3 + totalTimes[idx][1] / 1e6;
218 }
219
220 totalMS = totalMS.toFixed(2);
221 var rate = loopIterations * 1000 / totalMS;
222 rate = rate.toFixed(2);
223 console.log("interlaced inserts + coll.find() : " + totalMS + "ms (" + rate + " ops/s) " + loopIterations + " iterations");
224
225}
226
227// Find Interlaced Removes -> use linear customid for() loop find() and delete that obj when found
228function perfFindInterlacedRemoves() {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…