增加与 sqlite 对比评测的代码

This commit is contained in:
YuhangQ 2021-11-25 00:31:27 +08:00
parent 6327fde88b
commit 68b847e04a
9 changed files with 260127 additions and 3 deletions

1
benchmark/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules

BIN
benchmark/benchmark.sqlite Normal file

Binary file not shown.

47
benchmark/invodb.js Normal file
View File

@ -0,0 +1,47 @@
const invodb = require("invodb")
const { execSync } = require("child_process")
execSync("rm -rf benchmark.invodb")
let time = 0
function clock() {
let last = time
time = new Date().getTime()
return (time - last) / 1000
}
invodb.database("benchmark.invodb")
let User = invodb.collection("user")
User.create()
let arr = []
clock()
for(let i=0; i<10000; i++) {
let json = {
qq: randomString(11),
phone: randomString(11)
}
User.insert(json)
arr.push(json)
}
console.log("[TEST]插入" + clock())
for(let i=0; i<10000; i++) {
let res = User.findOne({
qq: arr[i].qq
})
console.log(res)
}
console.log("[TEST]查询" + clock())
function randomString(e) {
e = e || 32;
var t = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678",
a = t.length,
n = "";
for (i = 0; i < e; i++) n += t.charAt(Math.floor(Math.random() * a));
return n
}

16
benchmark/package.json Normal file
View File

@ -0,0 +1,16 @@
{
"name": "invodb-benchmark",
"version": "1.0.0",
"description": "测试invodb的性能",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"invodb": "^1.0.18",
"sequelize": "^6.9.0",
"sqlite3": "^5.0.2"
}
}

53
benchmark/sqlite.js Normal file
View File

@ -0,0 +1,53 @@
const { Sequelize, Model, DataTypes } = require('sequelize');
const { execSync } = require("child_process")
execSync("rm -rf benchmark.sqlite")
let time = 0
function clock() {
let last = time
time = new Date().getTime()
return (time - last) / 1000
}
const sequelize = new Sequelize({
dialect: 'sqlite',
storage: 'benchmark.sqlite'
});
const User = sequelize.define('user', {
qq: Sequelize.STRING(11),
phone: Sequelize.STRING(11)
});
(async () => {
clock()
await sequelize.sync();
let arr = []
for(let i=0; i<10000; i++) {
let json = {
qq: randomString(11),
phone: randomString(11)
}
const jane = await User.create(json);
arr.push(json)
}
console.log("[TEST]插入" + clock())
for(let i=0; i<10000; i++) {
let test = await User.findOne({where:{qq: arr[i].qq}})
console.log(test)
}
console.log("[TEST]查询" + clock())
})();
function randomString(e) {
e = e || 32;
var t = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678",
a = t.length,
n = "";
for (i = 0; i < e; i++) n += t.charAt(Math.floor(Math.random() * a));
return n
}

130004
benchmark/test.log Normal file

File diff suppressed because it is too large Load Diff

130004
benchmark/test2.log Normal file

File diff suppressed because it is too large Load Diff

View File

@ -47,5 +47,4 @@ let hr = person.query({
}
]
})
console.log(hr)
console.log(hr)

View File

@ -1,6 +1,6 @@
{
"name": "invodb",
"version": "1.0.22",
"version": "1.0.23",
"description": "a nosql json document database",
"main": "index.js",
"scripts": {