Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add initial benchmarks #108

Merged
merged 1 commit into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions benchmarks/datastore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import benchmark from 'nanobench'
import { createDataStore } from '../tests/helpers/datastore.js'

const datastore = await createDataStore({
dataTypes: [
{
name: 'example',
blockPrefix: '0',
schema: {
type: 'object',
properties: {
id: { type: 'string' },
version: { type: 'string' },
value: { type: 'string' },
created: { type: 'number' },
updated: { type: 'number' },
timestamp: { type: 'number' },
links: { type: 'array' },
forks: { type: 'array' },
authorId: { type: 'string' },
},
additionalProperties: false,
},
extraColumns: `
value TEXT,
created INTEGER,
updated INTEGER,
timestamp INTEGER,
authorId TEXT
`,
}
]
})

benchmark('create', async (b) => {
b.start()
for (let i = 0; i < 1000; i = i + 1) {
await datastore.create('example', {
value: `value ${i}`,
})
}
b.end()
})
37 changes: 37 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"lint": "eslint .",
"format": "prettier . --write",
"test": "brittle tests/*.js",
"bench": "nanobench benchmarks/*.js",
"type": "tsc",
"deps": "depcheck --ignore-dirs=docs,types --ignores=@types/*,typescript,typedoc,typedoc-plugin-markdown,@hyperswarm/testnet",
"doc": "typedoc --plugin typedoc-plugin-markdown --out docs/api",
Expand Down Expand Up @@ -51,6 +52,7 @@
"depcheck": "^1.4.3",
"eslint": "^8.30.0",
"eslint-config-prettier": "^8.5.0",
"nanobench": "^3.0.0",
"prettier": "^2.8.1",
"random-access-memory": "^6.1.0",
"rimraf": "^4.1.2",
Expand Down
27 changes: 27 additions & 0 deletions tests/helpers/datastore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import ram from 'random-access-memory'
import Corestore from 'corestore'
import b4a from 'b4a'

import { DataStore } from '../../lib/datastore/index.js'
import { Sqlite } from '../../lib/sqlite.js'

import { createIdentityKeys } from './index.js'

export async function createDataStore (options) {
const { dataTypes } = options
const { identityKeyPair, keyManager } = createIdentityKeys()
const keyPair = keyManager.getHypercoreKeypair('data', b4a.alloc(32))
const corestore = new Corestore(ram)
const sqlite = new Sqlite(':memory:')

const datastore = new DataStore({
corestore,
sqlite,
keyPair,
identityPublicKey: identityKeyPair.publicKey,
dataTypes
})

await datastore.ready()
return datastore
}
1 change: 1 addition & 0 deletions types/modules.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// - DhtNode

declare module 'brittle'
declare module 'nanobench'
declare module 'multi-core-indexer'
declare module '@mapeo/sqlite-indexer'
declare module 'sodium-universal'
Expand Down