Skip to content

Instantly share code, notes, and snippets.

@b3z
Created February 25, 2020 09:43
Show Gist options
  • Select an option

  • Save b3z/fcabecb030f40c899ebd53d7c5578804 to your computer and use it in GitHub Desktop.

Select an option

Save b3z/fcabecb030f40c899ebd53d7c5578804 to your computer and use it in GitHub Desktop.
A little benchmark for typescript pouchdb. Hell it is fast.
//import PouchDB from 'pouchdb';
var PouchDB = require('pouchdb');
PouchDB.plugin(require('pouchdb-quick-search'));
class Database {
db: any;
constructor(databaseName: string) {
this.db = new PouchDB(databaseName);
this.db.info().then(function () {
console.log('benchmarklocal Database online.');
}).catch(function () {
console.log('Error for benchmark Database.');
});
}
save(text: string): void {
this.db.post({
text: text
}).then(function (response: any) {
//console.log(response)
}).catch(function (err: any) {
console.log(err);
});
}
selectAll(): any {
this.db.search({
query: 'ananas',
fields: ['title', 'text'],
}).then(function (res: any) {
console.log(res)
}).catch(function (err: any) {
console.log(err);
});
}
}
let db = new Database("benchmark.pouch");
let words: string[] = ['ananas', 'golf', 'auto', 'kind', 'astronaut', 'TypeScriptKiddie', '123', 'papaya', 'weihnachtsmann', 'blaubeere', 'Paranoid'];
let datasets = 100000;
let data:string[] = new Array(datasets)
for (let i = 0; i < datasets; i++) { // datasets
data[i] = "benchmark "
for (let w = 0; w < 20; w++) { // build a sentence
var r = Math.floor(Math.random() * Math.floor(words.length - 1));
data[i] += words[r] + ' ';
}
}
console.log("All sentences generated.")
for (let y = 0; y < 10; y++) {
var d = new Date();
var n = d.getMilliseconds();
for (var s of data) {
db.save(s)
}
d = new Date();
var nn = d.getMilliseconds();
console.log(nn - n+"ms\n")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment