-
Notifications
You must be signed in to change notification settings - Fork 31
/
readBenchmark.js
59 lines (45 loc) · 1.3 KB
/
readBenchmark.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
const StormDB = require("../index.js");
const fs = require("fs");
const path = "./db.stormdb";
function parseToDP(num, dp) {
return num.toFixed(dp);
}
function deleteDB(path) {
fs.unlinkSync(path);
}
function createDatabase(num) {
const engine = new StormDB.localFileEngine(path);
const db = StormDB(engine);
for (let i = 0; i < num; i++) {
db.set(i, "val");
}
db.save();
}
function getFilesizeInBytes(filename) {
var stats = fs.statSync(filename);
var fileSizeInBytes = stats["size"];
return fileSizeInBytes / 1024 / 1024;
}
function runBenchmark(numberToInsert) {
if (fs.existsSync(path)) deleteDB(path);
createDatabase(numberToInsert);
/* start of core speed test */
let start = +new Date();
const engine = new StormDB.localFileEngine(path);
const db = StormDB(engine);
let end = +new Date();
/* end of core speed test */
let time = end - start;
let timeInSecs = time / 1000;
let sizeOfDB = getFilesizeInBytes(path);
let speedPerSec = parseToDP(numberToInsert / timeInSecs, 2);
console.log(`Number Read: ${numberToInsert}.
Time Elapsed: ${time}ms
Speed: ${speedPerSec}/sec
Size of Data Write: ${parseToDP(sizeOfDB, 2)}mb\n`);
}
console.log("Read Benchmarks:\n");
let numbers = [100000, 1000000, 10000000];
numbers.forEach(val => {
runBenchmark(val);
});