Benchmark - aalfiann/fly-json-odm GitHub Wiki
Benchmark test for WHERE with 1 Million object.
Tested in:
- Ubuntu 18.04
- Core i7
- Ram 8Gb
- SSD
- Node v10.16.3
- NPM v6.12.0
Note:
- Result will be different depend on your machine and your browser.
- This benchmark is only to look how fast query WHERE to find one data with
fly-json-odm
. - Shallow mode is 10x faster and good for handle big data.
TLDR;
Here is the benchmark to do queries with Fly Json ODM.
Most common queries with 1 million object arrays, tested in Real Browser.
Table of Contents
- 1. benchmark-sync.js
- 2. benchmark-async.js
- 3. benchmark-sync.js [Shallow Mode]
- 4. benchmark-async.js [Shallow Mode]
- 5. Benchmark in Browser
1. benchmark-sync.js
const FlyJson = require('fly-json-odm');
const nosql = new FlyJson();
var data = [];
var start = 1;
var end = 1000000;
console.log(new Date().toISOString().replace('T',' ').replace('Z','').substr(0,19));
console.log('Build '+end+' object datatable');
function buildObject() {
return new Promise((resolve,reject) => {
for(var i =start;i<=end;i++) {
data.push({ id:i, name:'user_'+i });
}
resolve();
});
}
buildObject().then(resolve => {
console.log(new Date().toISOString().replace('T',' ').replace('Z','').substr(0,19));
console.log(data.length+' object has been build');
console.log('======');
return resolve;
}).then(resolve => {
console.log('Set '+data.length+' object into nosql table: '+new Date().toISOString().replace('T',' ').replace('Z','').substr(0,19));
var time_start = Date.now();
// We separated the SET(data) because we only want to see how fast the query WHERE to find one data in data table
nosql.set(data);
var time_end = Date.now();
console.log('Total: '+ (time_end-time_start)+'ms');
console.log('======');
return resolve;
}).then(resolve => {
console.log('Start where at: '+new Date().toISOString().replace('T',' ').replace('Z','').substr(0,19))
var time_start = Date.now();
// WHERE IS BEGIN FROM HERE
var result = nosql.where('id',1000000).exec();
var time_end = Date.now();
console.log('Found at: '+new Date().toISOString().replace('T',' ').replace('Z','').substr(0,19));
console.log('Result: '+JSON.stringify(result));
console.log('Total: '+ (time_end-time_start)+'ms');
});
Result:
2019-11-02 01:17:13
Build 1000000 object datatable
2019-11-02 01:17:14
1000000 object has been build
======
Set 1000000 object into nosql table: 2019-11-02 01:17:14
Total: 312ms
======
Start where at: 2019-11-02 01:17:14
Found at: 2019-11-02 01:17:14
Result: [{"id":1000000,"name":"user_1000000"}]
Total: 68ms
2. benchmark-async.js
const FlyJson = require('fly-json-odm');
const nosql = new FlyJson();
var data = [];
var start = 1;
var end = 1000000;
console.log(new Date().toISOString().replace('T',' ').replace('Z','').substr(0,19));
console.log('Build '+end+' object datatable');
function buildObject() {
return new Promise((resolve,reject) => {
for(var i =start;i<=end;i++) {
data.push({ id:i, name:'user_'+i });
}
resolve();
});
}
buildObject().then(resolve => {
console.log(new Date().toISOString().replace('T',' ').replace('Z','').substr(0,19));
console.log(data.length+' object has been build');
console.log('======');
return resolve;
}).then(resolve => {
nosql.promisify(builder => { return builder}).then(table => {
console.log('Set '+data.length+' object into nosql table: '+new Date().toISOString().replace('T',' ').replace('Z','').substr(0,19));
var time_start = Date.now();
// We separated the SET(data) because we only want to see how fast the query WHERE to find one data in data table
var result = table.set(data);
var time_end = Date.now();
console.log('Total: '+ (time_end-time_start)+'ms');
console.log('======');
return result;
}).then(result => {
console.log('Start where at: '+new Date().toISOString().replace('T',' ').replace('Z','').substr(0,19))
var time_start = Date.now();
// WHERE IS BEGIN FROM HERE
var found = result.where('id',1000000).exec();
var time_end = Date.now();
console.log('Found at: '+new Date().toISOString().replace('T',' ').replace('Z','').substr(0,19));
console.log('Result: '+JSON.stringify(found));
console.log('Total: '+ (time_end-time_start)+'ms');
});
});
Result
2019-11-02 01:18:13
Build 1000000 object datatable
2019-11-02 01:18:13
1000000 object has been build
======
Set 1000000 object into nosql table: 2019-11-02 01:18:13
Total: 263ms
======
Start where at: 2019-11-02 01:18:14
Found at: 2019-11-02 01:18:14
Result: [{"id":1000000,"name":"user_1000000"}]
Total: 58ms
3. benchmark-sync.js [Shallow Mode]
const FlyJson = require('fly-json-odm');
const nosql = new FlyJson();
var data = [];
var start = 1;
var end = 1000000;
console.log(new Date().toISOString().replace('T',' ').replace('Z','').substr(0,19));
console.log('Build '+end+' object datatable');
function buildObject() {
return new Promise((resolve,reject) => {
for(var i =start;i<=end;i++) {
data.push({ id:i, name:'user_'+i });
}
resolve();
});
}
buildObject().then(resolve => {
console.log(new Date().toISOString().replace('T',' ').replace('Z','').substr(0,19));
console.log(data.length+' object has been build');
console.log('======');
return resolve;
}).then(resolve => {
console.log('Set '+data.length+' object into nosql table: '+new Date().toISOString().replace('T',' ').replace('Z','').substr(0,19));
var time_start = Date.now();
// SHALLOW MODE
nosql.setMode('shallow').set(data);
var time_end = Date.now();
console.log('Total: '+ (time_end-time_start)+'ms');
console.log('======');
return resolve;
}).then(resolve => {
console.log('Start where at: '+new Date().toISOString().replace('T',' ').replace('Z','').substr(0,19))
var time_start = Date.now();
// WHERE IS BEGIN FROM HERE
var result = nosql.where('id',1000000).exec();
var time_end = Date.now();
console.log('Found at: '+new Date().toISOString().replace('T',' ').replace('Z','').substr(0,19));
console.log('Result: '+JSON.stringify(result));
console.log('Total: '+ (time_end-time_start)+'ms');
});
Result:
2019-11-02 01:19:41
Build 1000000 object datatable
2019-11-02 01:19:41
1000000 object has been build
======
Set 1000000 object into nosql table: 2019-11-02 01:19:41
Total: 82ms
======
Start where at: 2019-11-02 01:19:41
Found at: 2019-11-02 01:19:41
Result: [{"id":1000000,"name":"user_1000000"}]
Total: 63ms
4. benchmark-async.js [Shallow Mode]
const FlyJson = require('fly-json-odm');
const nosql = new FlyJson();
var data = [];
var start = 1;
var end = 1000000;
console.log(new Date().toISOString().replace('T',' ').replace('Z','').substr(0,19));
console.log('Build '+end+' object datatable');
function buildObject() {
return new Promise((resolve,reject) => {
for(var i =start;i<=end;i++) {
data.push({ id:i, name:'user_'+i });
}
resolve();
});
}
buildObject().then(resolve => {
console.log(new Date().toISOString().replace('T',' ').replace('Z','').substr(0,19));
console.log(data.length+' object has been build');
console.log('======');
return resolve;
}).then(resolve => {
nosql.promisify(builder => { return builder}).then(table => {
console.log('Set '+data.length+' object into nosql table: '+new Date().toISOString().replace('T',' ').replace('Z','').substr(0,19));
var time_start = Date.now();
// SHALLOW MODE
var result = table.setMode('shallow').set(data);
var time_end = Date.now();
console.log('Total: '+ (time_end-time_start)+'ms');
console.log('======');
return result;
}).then(result => {
console.log('Start where at: '+new Date().toISOString().replace('T',' ').replace('Z','').substr(0,19))
var time_start = Date.now();
// WHERE IS BEGIN FROM HERE
var found = result.where('id',1000000).exec();
var time_end = Date.now();
console.log('Found at: '+new Date().toISOString().replace('T',' ').replace('Z','').substr(0,19));
console.log('Result: '+JSON.stringify(found));
console.log('Total: '+ (time_end-time_start)+'ms');
});
});
Result
2019-11-02 01:20:32
Build 1000000 object datatable
2019-11-02 01:20:32
1000000 object has been build
======
Set 1000000 object into nosql table: 2019-11-02 01:20:32
Total: 81ms
======
Start where at: 2019-11-02 01:20:32
Found at: 2019-11-02 01:20:32
Result: [{"id":1000000,"name":"user_1000000"}]
Total: 62ms
5. Benchmark in Real Browser
Let's us benchmark Fly Json ODM in real browser with 1 millions array objects.
- 1Million - Set the Table + Where (Deep and Shallow Mode)
- 10K - Set the Table + Where (Deep and Shallow Mode)
- QUERIES ONLY - Where, Limit, Paginate, Order