Skip to content

Commit

Permalink
Adding a reasonable data set for benchmarking
Browse files Browse the repository at this point in the history
  • Loading branch information
avoidwork committed Mar 18, 2017
1 parent 47f0aa2 commit 8e8cd51
Show file tree
Hide file tree
Showing 4 changed files with 45,090 additions and 95 deletions.
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
.travis.yml
Gruntfile.js
benchmark.js
bower.json
bower.json
data.json
163 changes: 78 additions & 85 deletions benchmark.js
Original file line number Diff line number Diff line change
@@ -1,97 +1,90 @@
const path = require("path"),
haro = require(path.join(__dirname, "lib", "haro.es6")),
precise = require("precise"),
nth = 15000,
data = [];
haro = require(path.join(__dirname, "lib", "haro.es6")),
precise = require("precise"),
data = require(path.join(__dirname, "data.json"));

let indexes;

let i = -1;

while (++i < nth) {
data.push({id: i, name: "abba " + i});
}

function second () {
const timer = precise().start(),
store = haro(null, {key: "id", index: ["name"]}),
deferreds = [];

deferreds.push(store.override(data, "records"));
deferreds.push(store.override(indexes, "indexes"));

Promise.all(deferreds).then(function () {
let i = -1,
nth = 5;

timer.stop();
console.log("time to override data: " + (timer.diff() / 1000000) + "ms");
console.log("testing time to 'search(regex, index)' on overridden data for a record (first one is cold):");

while (++i < nth) {
(function () {
const timer2 = precise().start();
const record = store.search(/abba 2342/, "name");
timer2.stop();
console.log((timer2.diff() / 1000000) + "ms");

if (!record) {
console.log("Couldn't find record");
}
}());
}
});
const timer = precise().start(),
store = haro(null, {key: "id", index: ["name"]}),
deferreds = [];

deferreds.push(store.override(data, "records"));
deferreds.push(store.override(indexes, "indexes"));

Promise.all(deferreds).then(function () {
let i = -1,
nth = 5;

timer.stop();
console.log("time to override data: " + (timer.diff() / 1000000) + "ms");
console.log("testing time to 'search(regex, index)' on overridden data for a record (first one is cold):");

while (++i < nth) {
(function () {
const timer2 = precise().start();
const record = store.search(/Carly Conway/, "name");
timer2.stop();
console.log((timer2.diff() / 1000000) + "ms");

if (!record) {
console.log("Couldn't find record");
}
}());
}
});
}

function first () {
const timer = precise().start(),
store = haro(null, {key: "id", index: ["name"]});

store.batch(data, "set").then(function () {
timer.stop();
console.log("time to batch insert data: " + (timer.diff() / 1000000) + "ms");
console.log("datastore record count: " + store.total);
console.log("name indexes: " + store.indexes.get("name").size);
}).then(function () {
let i = -1,
nth = 5;

console.log("testing time to 'find()' a record (first one is cold):");
indexes = store.dump("indexes");

while (++i < nth) {
(function () {
const timer2 = precise().start();
const record = store.find({name: "abba 12345"});
timer2.stop();
console.log((timer2.diff() / 1000000) + "ms");

if (!record) {
console.log("Couldn't find record");
}
}());
}
}).then(function () {
let i = -1,
nth = 5;

console.log("testing time to 'search(regex, index)' for a record (first one is cold):");

while (++i < nth) {
(function () {
const timer2 = precise().start();
const record = store.search(/abba 12345/, "name");
timer2.stop();
console.log((timer2.diff() / 1000000) + "ms");

if (!record) {
console.log("Couldn't find record");
}
}());
}

second();
});
store = haro(null, {key: "id", index: ["name"]});

store.batch(data, "set").then(function () {
timer.stop();
console.log("time to batch insert data: " + (timer.diff() / 1000000) + "ms");
console.log("datastore record count: " + store.total);
console.log("name indexes: " + store.indexes.get("name").size);
}).then(function () {
let i = -1,
nth = 5;

console.log("testing time to 'find()' a record (first one is cold):");
indexes = store.dump("indexes");

while (++i < nth) {
(function () {
const timer2 = precise().start();
const record = store.find({name: "Muriel Osborne"});
timer2.stop();
console.log((timer2.diff() / 1000000) + "ms");

if (!record) {
console.log("Couldn't find record");
}
}());
}
}).then(function () {
let i = -1,
nth = 5;

console.log("testing time to 'search(regex, index)' for a record (first one is cold):");

while (++i < nth) {
(function () {
const timer2 = precise().start();
const record = store.search(/Lizzie Clayton/, "name");
timer2.stop();
console.log((timer2.diff() / 1000000) + "ms");

if (!record) {
console.log("Couldn't find record");
}
}());
}

second();
});
}

first();
Expand Down
17 changes: 8 additions & 9 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,15 @@
],
"license": "BSD-3-Clause",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"src",
"test",
"tests",
"benchmark.js",
"Gruntfile.js",
"node_modules/*",
"src/*",
"test/*",
".eslintrc",
".gitignore",
".npmignore",
".travis.yml",
".npmignore"
"benchmark.js",
"Gruntfile.js",
"data.json"
]
}
Loading

0 comments on commit 8e8cd51

Please sign in to comment.