新建了个工程,用npm install bson安装了BSON库,写了下面的测试代码:
// Serialize document
var doc = {
name: "aafewfff",
level: 33,
job: 1,
attr: {
maxHP: 2123212.0,
phyAtk: 23424.22,
phyDef: 23242,
magAtk: 234234,
magDef: 232342,
},
}
var t = new Date().getTime();
for (var i = 0; i < 10000; ++i) {
// Serialize a document
var data = bson.serialize(doc)
// Deserialize the resulting Buffer
var doc_2 = bson.deserialize(data)
}
console.log(new Date().getTime() - t);
在浏览器里跑,打印出业的时间是:124ms
在原生版本里跑,时间是:2024ms
