Skip to content

Instantly share code, notes, and snippets.

@arselzer
Created March 19, 2014 19:03
Show Gist options
  • Save arselzer/9648887 to your computer and use it in GitHub Desktop.
Save arselzer/9648887 to your computer and use it in GitHub Desktop.
LevelDB is fast!
var levelup = require("levelup");
var crypto = require("crypto");
var db = levelup("./db");
var queries = [];
for (var i = 0; i < 100; i++) {
var randKey = crypto.randomBytes(8).toString("hex");
var randVal = crypto.randomBytes(16).toString("hex");
queries.push({
type: "put",
key: randKey,
value: randVal
});
}
var startTime = process.hrtime();
db.batch(queries, function(err) {
if (err) console.error(err);
console.log("Yay! Let's query");
db.createReadStream()
.on("data", function(data) {
console.log(data.key, ":", data.value);
})
.on("end", function() {
console.log("done");
var endTime = process.hrtime(startTime);
console.log("Speed(ms):", endTime[1] / 1000000);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment