forked from OptimalBits/fowl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench.js
96 lines (76 loc) · 2.04 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
"use strict";
var Benchmark = require('benchmark');
var fowl = require('./index');
var bluebird = require('bluebird');
fowl.open();
var suite = new Benchmark.Suite;
var mediumSize = {
name: 'John',
lastname: 'Smith',
address: 'Papegoya gatan 17',
city: 'Lomma',
country: 'Sweden',
balance: 500000,
interests: ['scuba diving', 'biking', 'reading', 'movies']
}
console.log("Running Benchmark")
var NUM_OBJECTS = 10000;
suite
.add('Create small objects, one per transaction', function(defer){
createObjects({
name: 'foo',
bar: 'baz'
}).then(function(){
defer.resolve();
})
}, {defer:true})
.add('Create small objects, one transaction', function(defer){
createObjectsOneTransaction({
name: 'foo',
bar: 'baz'
}).then(function(){
defer.resolve();
});
}, {defer:true})
.add('Create medium objects, one per transaction', function(defer){
createObjects(mediumSize).then(function(){
defer.resolve();
});
})
.add('Create medium objects, one transaction', function(defer){
createObjects(mediumSize).then(function(){
defer.resolve();
});
})
/*
.add('Create large objects, one per transaction', function(defer){
})
.add('Create large objects, one transaction', function(defer){
})
*/
.on('start', function(event){
console.log("Starting benchmark: "+event.target.name);
})
.on('cycle', function(event){
console.log(event.target.name,
"Mean: "+Math.round(event.target.stats.mean*1000)+'ms',
"Variance: "+Math.round(event.target.stats.variance*1000)+'ms');
})
.on('complete', function(){
console.log("All benchmarks completed");
})
.run();
function createObjects(data){
var ops = []
for(var i=0; i<NUM_OBJECTS; i++){
ops.push(fowl.create('benchmarks', data));
}
return bluebird.all(ops)
}
function createObjectsOneTransaction(data){
var tr = fowl.transaction();
for(var i=0; i<NUM_OBJECTS; i++){
tr.create('benchmarks', data);
}
return tr.commit();
}