Skip to content

Instantly share code, notes, and snippets.

@coboshm
Last active February 27, 2017 09:52
Show Gist options
  • Save coboshm/19b03136fc9d5f3e4946ab69f8e99e6e to your computer and use it in GitHub Desktop.
Save coboshm/19b03136fc9d5f3e4946ab69f8e99e6e to your computer and use it in GitHub Desktop.
Aggregation benchmark
var db = connect('localhost:27020/dev');
// timed queries
var numQueries = 1000, start = Date.now(), res;
for (var i = numQueries; i--;) {
res = db.scan.aggregate([
{ $match: { client_id: ObjectId("58b19c4872d797313163b8f4"), country: {$in: ["ITA", "FRA", "ES"]} } },
{ $group: { _id: "$summary_id", status: { $min: "$status"}, score: { $max: "$score"}}},
{ $sort: { created_at: 1} },
{ $limit: 100}
]);
}
var end = Date.now(),
totalSeconds = (end - start) / 1000,
avgSeconds = (totalSeconds / numQueries).toFixed(2);
print('Total time all queries ' + totalSeconds + ' seconds');
print('Query was executed ' + numQueries + ' times');
print('Average query time: ' + avgSeconds + ' seconds (' + ((end - start) / numQueries) + 'ms)');
#documents time without index time with index
400000 0.18seg 0.03seg
600000 0.26seg 0.03seg
800000 0.34seg 0.04seg
1000000 0.42seg 0.04seg
1500000 0.71seg 0.04seg
2800000 1.45seg 0.042seg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment