mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-03-30 15:08:28 +00:00
Fix nodejs benchmarks
This commit is contained in:
parent
53e8b35fc9
commit
8c7069a3a6
@ -33,7 +33,7 @@ import rmrf from 'rimraf'
|
||||
|
||||
const startTime1 = new Date().getTime()
|
||||
for (let i = 0; i < entryCount; i++) {
|
||||
await log.append(i.toString(), { pointerCount: 0 })
|
||||
await log.append(i.toString(), { referencesCount: 0 })
|
||||
}
|
||||
const endTime1 = new Date().getTime()
|
||||
const duration1 = endTime1 - startTime1
|
||||
|
83
benchmarks/orbitdb-events.js
Normal file
83
benchmarks/orbitdb-events.js
Normal file
@ -0,0 +1,83 @@
|
||||
import { createOrbitDB } from '../src/index.js'
|
||||
import rmrf from 'rimraf'
|
||||
import * as IPFS from 'ipfs-core'
|
||||
|
||||
import { EventEmitter } from 'events'
|
||||
EventEmitter.defaultMaxListeners = 10000
|
||||
|
||||
const ipfsConfig = {
|
||||
preload: {
|
||||
enabled: false
|
||||
},
|
||||
config: {
|
||||
Addresses: {
|
||||
API: '/ip4/127.0.0.1/tcp/0',
|
||||
Swarm: ['/ip4/0.0.0.0/tcp/0'],
|
||||
Gateway: '/ip4/0.0.0.0/tcp/0'
|
||||
},
|
||||
Bootstrap: [],
|
||||
Discovery: {
|
||||
MDNS: {
|
||||
Enabled: false,
|
||||
Interval: 0
|
||||
},
|
||||
webRTCStar: {
|
||||
Enabled: false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
;(async () => {
|
||||
console.log('Starting benchmark...')
|
||||
|
||||
const entryCount = 1000
|
||||
|
||||
await rmrf('./ipfs')
|
||||
await rmrf('./orbitdb')
|
||||
|
||||
const ipfs = await IPFS.create({ ...ipfsConfig, repo: './ipfs' })
|
||||
const orbitdb = await createOrbitDB({ ipfs })
|
||||
|
||||
console.log(`Create ${entryCount} events`)
|
||||
|
||||
const db1 = await orbitdb.open('benchmark-events')
|
||||
|
||||
const startTime1 = new Date().getTime()
|
||||
|
||||
for (let i = 0; i < entryCount; i++) {
|
||||
await db1.add(i.toString())
|
||||
}
|
||||
|
||||
const endTime1 = new Date().getTime()
|
||||
const duration1 = endTime1 - startTime1
|
||||
const operationsPerSecond1 = Math.floor(entryCount / (duration1 / 1000))
|
||||
const millisecondsPerOp1 = duration1 / entryCount
|
||||
console.log(`Creating ${entryCount} events took ${duration1} ms, ${operationsPerSecond1} ops/s, ${millisecondsPerOp1} ms/op`)
|
||||
|
||||
console.log(`Iterate ${entryCount} events`)
|
||||
const startTime2 = new Date().getTime()
|
||||
|
||||
const all = []
|
||||
for await (const { key, value } of db1.iterator()) {
|
||||
all.unshift({ key, value })
|
||||
}
|
||||
|
||||
const endTime2 = new Date().getTime()
|
||||
const duration2 = endTime2 - startTime2
|
||||
const operationsPerSecond2 = Math.floor(entryCount / (duration2 / 1000))
|
||||
const millisecondsPerOp2 = duration2 / entryCount
|
||||
|
||||
console.log(`Iterating ${all.length} events took ${duration2} ms, ${operationsPerSecond2} ops/s, ${millisecondsPerOp2} ms/op`)
|
||||
|
||||
await db1.drop()
|
||||
await db1.close()
|
||||
|
||||
await orbitdb.stop()
|
||||
await ipfs.stop()
|
||||
|
||||
await rmrf('./ipfs')
|
||||
await rmrf('./orbitdb')
|
||||
|
||||
process.exit(0)
|
||||
})()
|
@ -1,18 +1,14 @@
|
||||
import { OrbitDB } from '../src/index.js'
|
||||
import { createOrbitDB } from '../src/index.js'
|
||||
import rmrf from 'rimraf'
|
||||
import * as IPFS from 'ipfs-core'
|
||||
|
||||
import { EventEmitter } from 'events'
|
||||
|
||||
EventEmitter.defaultMaxListeners = 10000
|
||||
|
||||
const ipfsConfig = {
|
||||
preload: {
|
||||
enabled: false
|
||||
},
|
||||
EXPERIMENTAL: {
|
||||
pubsub: true
|
||||
},
|
||||
config: {
|
||||
Addresses: {
|
||||
API: '/ip4/127.0.0.1/tcp/0',
|
||||
@ -41,7 +37,7 @@ const ipfsConfig = {
|
||||
await rmrf('./orbitdb')
|
||||
|
||||
const ipfs = await IPFS.create({ ...ipfsConfig, repo: './ipfs' })
|
||||
const orbitdb = await OrbitDB({ ipfs })
|
||||
const orbitdb = await createOrbitDB({ ipfs })
|
||||
|
||||
console.log(`Set ${entryCount} keys/values`)
|
||||
|
||||
|
@ -1,20 +1,16 @@
|
||||
import { OrbitDB } from '../src/index.js'
|
||||
import { createOrbitDB } from '../src/index.js'
|
||||
import rmrf from 'rimraf'
|
||||
import * as IPFS from 'ipfs-core'
|
||||
import connectPeers from '../test/utils/connect-nodes.js'
|
||||
import waitFor from '../test/utils/wait-for.js'
|
||||
|
||||
import { EventEmitter } from 'events'
|
||||
|
||||
EventEmitter.defaultMaxListeners = 10000
|
||||
|
||||
const ipfsConfig = {
|
||||
preload: {
|
||||
enabled: false
|
||||
},
|
||||
EXPERIMENTAL: {
|
||||
pubsub: true
|
||||
},
|
||||
config: {
|
||||
Addresses: {
|
||||
API: '/ip4/127.0.0.1/tcp/0',
|
||||
@ -46,8 +42,8 @@ const ipfsConfig = {
|
||||
|
||||
const ipfs1 = await IPFS.create({ ...ipfsConfig, repo: './ipfs1' })
|
||||
const ipfs2 = await IPFS.create({ ...ipfsConfig, repo: './ipfs2' })
|
||||
const orbitdb1 = await OrbitDB({ ipfs: ipfs1, directory: './orbitdb1' })
|
||||
const orbitdb2 = await OrbitDB({ ipfs: ipfs2, directory: './orbitdb2' })
|
||||
const orbitdb1 = await createOrbitDB({ ipfs: ipfs1, directory: './orbitdb1' })
|
||||
const orbitdb2 = await createOrbitDB({ ipfs: ipfs2, directory: './orbitdb2' })
|
||||
|
||||
await connectPeers(ipfs1, ipfs2)
|
||||
|
||||
@ -77,7 +73,7 @@ const ipfsConfig = {
|
||||
|
||||
await waitFor(() => connected, () => true)
|
||||
|
||||
console.log(`Iterate ${entryCount} events`)
|
||||
console.log(`Iterate ${entryCount} events to replicate them`)
|
||||
const startTime2 = new Date().getTime()
|
||||
|
||||
const all = []
|
||||
@ -90,7 +86,7 @@ const ipfsConfig = {
|
||||
const operationsPerSecond2 = Math.floor(entryCount / (duration2 / 1000))
|
||||
const millisecondsPerOp2 = duration2 / entryCount
|
||||
|
||||
console.log(`Iterating ${all.length} events took ${duration2} ms, ${operationsPerSecond2} ops/s, ${millisecondsPerOp2} ms/op`)
|
||||
console.log(`Replicating ${all.length} events took ${duration2} ms, ${operationsPerSecond2} ops/s, ${millisecondsPerOp2} ms/op`)
|
||||
|
||||
await db1.drop()
|
||||
await db1.close()
|
||||
|
Loading…
x
Reference in New Issue
Block a user