Created
March 19, 2014 19:03
-
-
Save arselzer/9648887 to your computer and use it in GitHub Desktop.
LevelDB is fast!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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