forked from trz211/segment_tree_db_test2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (44 loc) · 1.32 KB
/
index.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
const dbConnector = require('./src/db/dbconnector');
const TreeReader = require('./src/tree/reader');
const TreeWriter = require('./src/tree/writer');
const treeReader = new TreeReader();
const treeWriter = new TreeWriter();
const {StopWatch} = require('stopwatch-node');
const sw = new StopWatch();
//generate example
(async () => {
const now = new Date();
now.setMilliseconds(0);
for(let i = 0; i < 1000000; i ++){
if(i % 10000 === 0) console.log(i);
now.setMilliseconds(now.getMilliseconds() + 100);
if(Math.floor(Math.random() * 100) > 98){
now.setSeconds(now.getSeconds() + 1);
now.setMilliseconds(0);
continue;
}
if(Math.floor(Math.random() * 100) > 50){
continue;
}
const item = {
id: i.toString(),
val: Math.floor(Math.random() * 10),
time: now.toISOString()
};
const {id, ...treeItem} = item;
treeItem.start_time = now.toISOString();
treeItem.end_time = now.toISOString();
await dbConnector.insertItemOnExample(item);
await treeWriter.addItem(treeItem);
}
});
//search test
(async () => {
sw.start('range');
console.log(await dbConnector.getSumOfExample('2022-02-24T06:05:30.100Z', '2022-02-24T06:35:30.100Z'));
sw.stop();
sw.start('tree');
console.log(await treeReader.searchRange('2022-02-24T06:05:30.100Z', '2022-02-24T06:35:30.100Z'));
sw.stop();
sw.prettyPrint();
})();