import ping table
install
run q.js
{ | |
"dependencies": { | |
"ascii-progress": "^1.0.5", | |
"async": "^2.1.5", | |
"bluebird": "^3.4.7", | |
"rethinkdbdash": "^2.3.28" | |
} | |
} |
const r = require('rethinkdbdash')(); | |
const Promise = require('bluebird'); | |
const async = Promise.promisifyAll(require('async')); | |
const start = new Date(new Date().setDate(new Date().getDate() - 1)); | |
function benchmark(method) { | |
const start = +(new Date); | |
method && method(function (callback) { | |
const end = +(new Date); | |
const difference = end - start; | |
callback && callback(start, end, { | |
milliseconds: difference, | |
ms: difference, | |
seconds: (difference / 1000) % 60, | |
minutes: (difference / (1000 * 60)) % 60, | |
hours: (difference / (1000 * 60 * 60)) % 24 | |
}); | |
}); | |
} | |
R(() => { | |
NR(); | |
}); | |
function R(e) { | |
benchmark((end) => { | |
r.db('iserv').table('ping').filter(function (doc) { | |
return doc('date').during(start, new Date()); | |
}).count().run().then((c) => { | |
end((start, end, difference) => { | |
console.log('(R) Processed in: ' + difference.ms + 'ms!'); | |
console.log(c); | |
e(); | |
}) | |
}); | |
}); | |
} | |
function NR() { | |
benchmark((end) => { | |
r.db('iserv').table('ping').then(Items => { | |
const Count = Items.length; | |
const Ergebnis = []; | |
return async.eachAsync(Items, (Item, Callback) => { | |
if (Item.date > start && Item.date < new Date()) { | |
Ergebnis.push(Item); | |
Callback(null); | |
} else { | |
Callback(null); | |
} | |
}).then(() => { | |
end((start, end, difference) => { | |
console.log('(NR) Processed in: ' + difference.ms + 'ms!'); | |
console.log(Ergebnis.length); | |
}); | |
}); | |
}); | |
}); | |
} |