|
|
|
@ -1,5 +1,5 @@ |
|
|
|
|
/* eslint-env mocha, browser */ |
|
|
|
|
/* global async, Nedb, localforage */ |
|
|
|
|
/* global Nedb, localforage, testUtils */ |
|
|
|
|
|
|
|
|
|
const N = 5000 |
|
|
|
|
const db = new Nedb({ filename: 'loadTest', autoload: true }) |
|
|
|
@ -9,7 +9,7 @@ const sample = JSON.stringify({ data: Math.random(), _id: Math.random() }) |
|
|
|
|
const someInserts = (sn, N, callback) => { |
|
|
|
|
const beg = Date.now() |
|
|
|
|
let i = 0 |
|
|
|
|
async.whilst(() => i < N, _cb => { |
|
|
|
|
testUtils.whilst(() => i < N, _cb => { |
|
|
|
|
db.insert({ data: Math.random() }, err => { i += 1; return _cb(err) }) |
|
|
|
|
}, err => { |
|
|
|
|
console.log('Inserts, series ' + sn + ' ' + (Date.now() - beg)) |
|
|
|
@ -41,7 +41,7 @@ const someLSDiff = (sn, N, callback) => { |
|
|
|
|
function someLF (sn, N, callback) { |
|
|
|
|
const beg = Date.now() |
|
|
|
|
let i = 0 |
|
|
|
|
async.whilst(() => i < N, _cb => { |
|
|
|
|
testUtils.whilst(() => i < N, _cb => { |
|
|
|
|
localforage.getItem('loadTestLF', (err, value) => { |
|
|
|
|
if (err) return _cb(err) |
|
|
|
|
localforage.setItem('loadTestLF', value + sample, err => { i += 1; return _cb(err) }) |
|
|
|
@ -56,7 +56,7 @@ function someLF (sn, N, callback) { |
|
|
|
|
const someLFDiff = (sn, N, callback) => { |
|
|
|
|
const beg = Date.now() |
|
|
|
|
let i = 0 |
|
|
|
|
async.whilst(() => i < N, _cb => { |
|
|
|
|
testUtils.whilst(() => i < N, _cb => { |
|
|
|
|
localforage.setItem('loadTestLF-' + i, sample, err => { i += 1; return _cb(err) }) |
|
|
|
|
}, err => { |
|
|
|
|
console.log('localForage/IDB, series ' + sn + ' ' + (Date.now() - beg)) |
|
|
|
@ -72,54 +72,54 @@ describe.skip('Load tests', function () { |
|
|
|
|
db.remove({}, { multi: true }, err => done(err)) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
it.skip('Inserts', function (done) { |
|
|
|
|
async.waterfall([ |
|
|
|
|
it('Inserts', function (done) { |
|
|
|
|
testUtils.waterfall([ |
|
|
|
|
// Slow and gets slower with database size
|
|
|
|
|
async.apply(someInserts, '#1', N), // N=5000, 141s
|
|
|
|
|
async.apply(someInserts, '#2', N), // N=5000, 208s
|
|
|
|
|
async.apply(someInserts, '#3', N), // N=5000, 281s
|
|
|
|
|
async.apply(someInserts, '#4', N) // N=5000, 350s
|
|
|
|
|
testUtils.apply(someInserts, '#1', N), // N=5000, 141s
|
|
|
|
|
testUtils.apply(someInserts, '#2', N), // N=5000, 208s
|
|
|
|
|
testUtils.apply(someInserts, '#3', N), // N=5000, 281s
|
|
|
|
|
testUtils.apply(someInserts, '#4', N) // N=5000, 350s
|
|
|
|
|
], done) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
it.skip('Localstorage', function (done) { |
|
|
|
|
async.waterfall([ |
|
|
|
|
it('Localstorage', function (done) { |
|
|
|
|
testUtils.waterfall([ |
|
|
|
|
// Slow and gets slower really fast with database size, then outright crashes
|
|
|
|
|
async.apply(someLS, '#1', N), // N=4000, 2.5s
|
|
|
|
|
async.apply(someLS, '#2', N), // N=4000, 8.0s
|
|
|
|
|
async.apply(someLS, '#3', N), // N=4000, 26.5s
|
|
|
|
|
async.apply(someLS, '#4', N) // N=4000, 47.8s then crash, can't get string (with N=5000 crash happens on second pass)
|
|
|
|
|
testUtils.apply(someLS, '#1', N), // N=4000, 2.5s
|
|
|
|
|
testUtils.apply(someLS, '#2', N), // N=4000, 8.0s
|
|
|
|
|
testUtils.apply(someLS, '#3', N), // N=4000, 26.5s
|
|
|
|
|
testUtils.apply(someLS, '#4', N) // N=4000, 47.8s then crash, can't get string (with N=5000 crash happens on second pass)
|
|
|
|
|
], done) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
it.skip('Localstorage Diff', function (done) { |
|
|
|
|
async.waterfall([ |
|
|
|
|
it('Localstorage Diff', function (done) { |
|
|
|
|
testUtils.waterfall([ |
|
|
|
|
// Much faster and more consistent
|
|
|
|
|
async.apply(someLSDiff, '#1', N), // N=50000, 0.7s
|
|
|
|
|
async.apply(someLSDiff, '#2', N), // N=50000, 0.5s
|
|
|
|
|
async.apply(someLSDiff, '#3', N), // N=50000, 0.5s
|
|
|
|
|
async.apply(someLSDiff, '#4', N) // N=50000, 0.5s
|
|
|
|
|
testUtils.apply(someLSDiff, '#1', N), // N=50000, 0.7s
|
|
|
|
|
testUtils.apply(someLSDiff, '#2', N), // N=50000, 0.5s
|
|
|
|
|
testUtils.apply(someLSDiff, '#3', N), // N=50000, 0.5s
|
|
|
|
|
testUtils.apply(someLSDiff, '#4', N) // N=50000, 0.5s
|
|
|
|
|
], done) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
it.skip('LocalForage', function (done) { |
|
|
|
|
async.waterfall([ |
|
|
|
|
it('LocalForage', function (done) { |
|
|
|
|
testUtils.waterfall([ |
|
|
|
|
// Slow and gets slower with database size
|
|
|
|
|
cb => { localforage.setItem('loadTestLF', '', err => cb(err)) }, |
|
|
|
|
async.apply(someLF, '#1', N), // N=5000, 69s
|
|
|
|
|
async.apply(someLF, '#2', N), // N=5000, 108s
|
|
|
|
|
async.apply(someLF, '#3', N), // N=5000, 137s
|
|
|
|
|
async.apply(someLF, '#4', N) // N=5000, 169s
|
|
|
|
|
testUtils.apply(someLF, '#1', N), // N=5000, 69s
|
|
|
|
|
testUtils.apply(someLF, '#2', N), // N=5000, 108s
|
|
|
|
|
testUtils.apply(someLF, '#3', N), // N=5000, 137s
|
|
|
|
|
testUtils.apply(someLF, '#4', N) // N=5000, 169s
|
|
|
|
|
], done) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
it.skip('LocalForage diff', function (done) { |
|
|
|
|
async.waterfall([ |
|
|
|
|
it('LocalForage diff', function (done) { |
|
|
|
|
testUtils.waterfall([ |
|
|
|
|
// Quite fast and speed doesn't change with database size (tested with N=10000 and N=50000, still no slow-down)
|
|
|
|
|
async.apply(someLFDiff, '#1', N), // N=5000, 18s
|
|
|
|
|
async.apply(someLFDiff, '#2', N), // N=5000, 18s
|
|
|
|
|
async.apply(someLFDiff, '#3', N), // N=5000, 18s
|
|
|
|
|
async.apply(someLFDiff, '#4', N) // N=5000, 18s
|
|
|
|
|
testUtils.apply(someLFDiff, '#1', N), // N=5000, 18s
|
|
|
|
|
testUtils.apply(someLFDiff, '#2', N), // N=5000, 18s
|
|
|
|
|
testUtils.apply(someLFDiff, '#3', N), // N=5000, 18s
|
|
|
|
|
testUtils.apply(someLFDiff, '#4', N) // N=5000, 18s
|
|
|
|
|
], done) |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|