/
bench.js
43 lines (35 loc) · 823 Bytes
/
bench.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
var exists = require('./');
var level = require('level');
var ben = require('ben');
var db = level(__dirname + '/db');
var big = '';
for (var i = 0; i < 400329; i++) {
big += 'abcdefghijklmnopqrstuvwxyz';
}
db.del('foo', function() {
console.log('empty');
check(function() {
console.log('small');
db.put('foo', 'bar', function() {
check(function() {
console.log('big');
db.put('foo', big, function() {
check();
});
});
});
});
});
function check(fn) {
ben.async(function(done) {
db.get('foo', done);
}, function(ms) {
console.log('get: %s ms per iteration', ms);
ben.async(function(done) {
exists(db, 'foo', done);
}, function(ms) {
console.log('exists: %s ms per iteration', ms);
if (fn) fn();
});
});
}