Verified Commit a423acb6 authored by Aral Balkan's avatar Aral Balkan
Browse files

Update Timing, readme

parent 57da3bea
......@@ -21,7 +21,7 @@ const WhatDB = require('.')
// Create your database in the test folder.
// (This is where your JSON files – “tables” – will be saved.)
const db = new WhatDB('test')
const db = new WhatDB('db')
// Create test/people.json with some data.
db.people = [
......@@ -42,12 +42,14 @@ After running the above script, try this one:
const WhatDB = require('.')
// This will load test database with the people table we created earlier.
const db = new WhatDB('test')
const db = new WhatDB('db')
// Let’s make sure Oskar’s in there… ;)
console.log(db.people[2])
```
(You can find these in the `examples/basic` folder of the source code, in the `run-me-first.js` and `run-me-next.js` scripts, respectively.)
## Use case
A data layer for simple [Small Web](https://ar.al/2020/08/07/what-is-the-small-web/) sites for basic public (e.g., anonymous comments on articles) or configuration data. Built for use in [Site.js](https://sitejs.org).
......@@ -72,6 +74,33 @@ A data layer for simple [Small Web](https://ar.al/2020/08/07/what-is-the-small-w
- __No schema, no migrations__: again, this is meant to be a very simple persistence, query, and observation layer for local data. If you want schemas and migrations, take a look at nearly every other database out there. You might also want to see how well [ObjectModel](https://github.com/sylvainpolletvillard/ObjectModel) works alongside WhatDB.
## Performance characteristics
With the caveat, once again, that this is __for small data sets__, it is still insightful to see the performance on my development machine (Intel i7-8550U (8) @ 4.000GHz, 16GB RAM) with what I would consider an order of magnitude larger data set than the limit you should be using with this module.
With `examples/performance` run to generate 1,000,000 records, taking up ~179MB on disk, with records similar to:
```json
[
{
"id": "b01b0c58-7b38-49f7-b2a1-06245525df57",
"domain": "coremax.me",
"email": "stephen.brandt@coremax.me",
"stripeId": "ff1a984b-a3a3-4332-9fc4-4f8315e8f6b7"
}
]
We currently get performance in the ballpark of:
### Reads
- 0.00025ms (Node.js native reads clock at ~0.00005ms)
### Writes
- Serialisation (synchronous): 0.246 ms
- Persisting to disk (asynchronous): 800-900ms
## Related projects, inspiration, etc.
- [proxy-fun](https://github.com/mikaelbr/awesome-es2015-proxy)
......
......@@ -2,6 +2,7 @@ const WhatDB = require('../..')
const dummyJSON = require('dummy-json')
const { performance } = require('perf_hooks')
const process = require('process')
const Time = require('../../lib/Time')
const fs = require('fs-extra')
const path = require('path')
......@@ -78,5 +79,13 @@ setTimeout(() => {
console.log('2 >>>', db.accounts[db.accounts.length/2].domain)
}, 100)
const timings = []
for (let i = 0; i < db.accounts.length; i++) {
Time.mark()
db.accounts[i]
timings.push(Time.elapsed(-1))
}
console.log(`Gets took on average (${db.accounts.length} tries): ${(timings.reduce((p, c) => p + c, 0)/db.accounts.length).toFixed(5)}`)
const used = process.memoryUsage().heapUsed / 1024 / 1024;
console.log(`The script uses approximately ${Math.round(used * 100) / 100} MB`);
......@@ -6,11 +6,11 @@ class Time {
this.startTime = performance.now()
}
static elapsed () {
static elapsed (precision = 3) {
const endTime = performance.now()
const duration = (endTime - this.startTime).toFixed(3)
const duration = endTime - this.startTime
this.startTime = endTime
return duration
return precision < 0 ? duration : duration.toFixed(precision)
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment