-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench.js
46 lines (42 loc) · 1.25 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
const Query = require('./src/Query/Query');
const Collection = require('./src/Base/Collection');
let collection = new Collection({}, {data: {}, getIndices: () => []});
collection.getIndexManager().createIndex('name', 'BTree');
collection.getIndexManager().createIndex('surname', 'BTree');
let query = new Query({
'and': [
{'eq': {'name': 'Thomas'}},
{'eq': {'surname': 'Buxhofer'}}
]
}, collection);
let testData = [
{name: 'Markus', surname: 'Nachbaur'},
{name: 'Matthias', surname: 'Buxhofer'},
{name: 'Michele', surname: 'Paonne'},
{name: 'Thomas', surname: 'Buxhofer'},
{name: 'Sandra', surname: 'Urach'},
{name: 'Silvijo', surname: 'Leben'},
{name: 'Stefan', surname: 'Hammerl'},
{name: 'Thomas', surname: 'Dallapiccola'},
{name: 'Torsten', surname: 'Passow'},
{name: 'Andreas', surname: 'Stückler'}
];
let benchData = [];
let i = 1;
while(i--){
let i2 = 10;
while(i2-- ) {
let doc = Object.assign({}, testData[i2]);
collection.insertOne(doc);
}
}
console.log("data count:", Object.values(collection.data()).length);
console.time('single query');
console.log(query.run(collection,collection.data()));
console.timeEnd('single query');
console.time('bench');
i = 1;
while(i--) {
query.run(collection, collection.data());
}
console.timeEnd('bench');