Skip to content

Commit

Permalink
Updating README.md, .npmignore, adding precise dev dependency for `…
Browse files Browse the repository at this point in the history
…benchmark.js`
  • Loading branch information
avoidwork committed Apr 7, 2021
1 parent 06a75dd commit a9e3e06
Show file tree
Hide file tree
Showing 6 changed files with 45,133 additions and 24 deletions.
4 changes: 3 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
.eslintrc
.gitignore
.travis.yml
rollup.config.js
benchmark.js
rollup.config.js
data.json
46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,31 +67,31 @@ A benchmark is included in the repository, and is useful for gauging how haro wi

```
Batch successful on test
time to batch insert data: 58.500052ms
time to batch insert data: 26.774208 ms
datastore record count: 1000
name indexes: 1000
testing time to 'find()' a record (first one is cold):
0.194559ms
0.030232ms
0.009265ms
0.006583ms
0.005852ms
0.10475ms
0.005792ms
0.003458ms
0.005166ms
0.009584ms
testing time to 'search(regex, index)' for a record (first one is cold):
0.720213ms
0.160183ms
0.114591ms
0.110933ms
0.112396ms
0.193834ms
0.110333ms
0.103875ms
0.10325ms
0.125833ms
time to override data: 5.041485ms
time to override data: 0.450125 ms
testing time to 'search(regex, index)' on overridden data for a record (first one is cold):
0.129219ms
0.113127ms
0.106789ms
0.105081ms
0.104594ms
0.260542ms
0.099792ms
0.097ms
0.09825ms
0.098334ms
```

### Configuration
Expand Down Expand Up @@ -209,7 +209,7 @@ _Map_

### API
**batch(array, type)**
_Promise_
_Array_

The first argument must be an `Array`, and the second argument must be `del` or `set`.

Expand Down Expand Up @@ -247,7 +247,7 @@ store.clear();
```

**del(key)**
_Promise_
_Undefined_

Deletes the record.

Expand Down Expand Up @@ -441,9 +441,9 @@ store.map(function (value) {
```

**override(data[, type="records", fn])**
_Promise_
_Boolean_

Returns a `Promise` for the new state. This is meant to be used in a paired override of the indexes & records, such that
This is meant to be used in a paired override of the indexes & records, such that
you can avoid the `Promise` based code path of a `batch()` insert or `load()`. Accepts an optional third parameter to perform the
transformation to simplify cross domain issues.

Expand Down Expand Up @@ -520,9 +520,9 @@ store.batch(data, 'set').then(function () {
```

**set(key, data, batch=false, override=false)**
_Promise_
_Object_

Returns a `Promise` for setting/amending a record in the DataStore, if `key` is `false` a version 4 `UUID` will be
Record in the DataStore. If `key` is `false` a version 4 `UUID` will be
generated.

If `override` is `true`, the existing record will be replaced instead of amended.
Expand Down
88 changes: 88 additions & 0 deletions benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
const path = require("path"),
{haro} = require(path.join(__dirname, "dist", "haro.cjs.js")),
precise = require("precise"),
data = require(path.join(__dirname, "data.json"));

let indexes;

function second () {
const timer = precise().start(),
store = haro(null, {id: "test", key: "_id", index: ["name", "eyeColor", "age", "gender", "isActive"]});
let i, nth;

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

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) {
const timer2 = precise().start(),
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, {id: "test", key: "_id", index: ["name", "eyeColor", "age", "gender", "isActive"]});
let i, nth;

store.batch(data, "set");
timer.stop();
console.log(`time to batch insert data: ${timer.diff() / 1000000} ms`);
console.log(`datastore record count: ${store.size}`);
console.log(`name indexes: ${store.indexes.get("name").size}\n`);

i = -1;
nth = 5;

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

while (++i < nth) {
const timer2 = precise().start(),
record = store.find({name: "Muriel Osborne"});

timer2.stop();
console.log(timer2.diff() / 1000000 + "ms");

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

console.log("");

i = -1;
nth = 5;

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

while (++i < nth) {
const timer2 = precise().start(),
record = store.search(/Lizzie Clayton/, "name");

timer2.stop();
console.log(timer2.diff() / 1000000 + "ms");

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

console.log("");
second();
}

first();
Loading

0 comments on commit a9e3e06

Please sign in to comment.