Skip to content

Instantly share code, notes, and snippets.

@rjcorwin
Last active January 29, 2019 12:13
Show Gist options
  • Save rjcorwin/9a28311bb83fa3a585e0a3830764abd9 to your computer and use it in GitHub Desktop.
Save rjcorwin/9a28311bb83fa3a585e0a3830764abd9 to your computer and use it in GitHub Desktop.
var numberOfDocs = 1000
var userName = 'RJ'
var templateDoc = {
yourDocHere: true
}
var fillUp = async (numberOfDocs, templateDoc, dbName) => {
let initialEstimate = await navigator.storage.estimate()
let db = new PouchDB(dbName)
delete templateDoc._rev
let i = 0
while (numberOfDocs > i) {
let doc = Object.assign({}, templateDoc, { _id: `${i}` })
await db.put(doc)
i++
}
let concludingEstimate = await navigator.storage.estimate()
console.log(`
Initial Estimate: ${JSON.stringify(initialEstimate)}
Concluding estimate: ${JSON.stringify(concludingEstimate)}
Usage Difference: ${concludingEstimate.usage - initialEstimate.usage} bytes
Average Doc Size: ${(concludingEstimate.usage - initialEstimate.usage) / numberOfDocs} bytes
`)
}
fillUp(numberOfDocs, templateDoc, userName)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment