Skip to content
This repository has been archived by the owner on Sep 30, 2023. It is now read-only.

new benchmarker/benchmarks; keeps old benchmarks #329

Closed
wants to merge 1 commit into from
Closed
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
37 changes: 37 additions & 0 deletions benchmarks/append.benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use strict'
const Ipfs = require('ipfs')
const { createLog, height } = require('./utils')

async function benchmark (benchmarker) {
const ipfs = await Ipfs.create({ repo: benchmarker.dir + '/ipfs' })
const { log } = await createLog(ipfs, 'A')

let i = 0
let appends = 0
benchmarker.trackMemory()
benchmarker.addMetric({
name: 'appends',
get: () => i
})
benchmarker.addMetric({
name: 'appends per second',
get: () => {
const perSecond = i - appends
appends = i
return perSecond
}
})

benchmarker.log('appending the log...')
benchmarker.startRecording()
for (; i < height; i++) {
await log.append(Date.now(), 32)
}
benchmarker.stopRecording()

await ipfs.stop()
}

module.exports = {
benchmark
}
21 changes: 21 additions & 0 deletions benchmarks/find-heads.benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict'
const Ipfs = require('ipfs')
const Log = require('../src/log')
const { createLog, height, appendEntries } = require('./utils')

async function benchmark (benchmarker) {
const ipfs = await Ipfs.create({ repo: benchmarker.dir + '/ipfs' })
const { log } = await createLog(ipfs, 'A')

const { entries } = await appendEntries(log, height, { withEntries: true })

benchmarker.startRecording()
Log.findHeads(entries)
benchmarker.stopRecording()

await ipfs.stop()
}

module.exports = {
benchmark
}
22 changes: 22 additions & 0 deletions benchmarks/from-entry-hash.benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict'
const Ipfs = require('ipfs')
const Log = require('../src/log')
const { createLog, height, appendEntries } = require('./utils')

async function benchmark (benchmarker) {
const ipfs = await Ipfs.create({ repo: benchmarker.dir + '/ipfs' })
const { log, identity, access } = await createLog(ipfs, 'A')

await appendEntries(log, height, { refCount: 64 })

benchmarker.trackMemory()
benchmarker.startRecording()
await Log.fromEntryHash(ipfs, identity, log.heads.map(e => e.hash), { access, logId: log._id })
benchmarker.stopRecording()

await ipfs.stop()
}

module.exports = {
benchmark
}
23 changes: 23 additions & 0 deletions benchmarks/get.benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict'
const Ipfs = require('ipfs')
const { createLog, height, appendEntries } = require('./utils')

async function benchmark (benchmarker) {
const ipfs = await Ipfs.create({ repo: benchmarker.dir + '/ipfs' })
const { log } = await createLog(ipfs, 'A')

await appendEntries(log, height)
const values = log.values

benchmarker.startRecording()
for (const { hash } of values) {
log.get(hash)
}
benchmarker.stopRecording()

await ipfs.stop()
}

module.exports = {
benchmark
}
23 changes: 23 additions & 0 deletions benchmarks/has.benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict'
const Ipfs = require('ipfs')
const { createLog, height, appendEntries } = require('./utils')

async function benchmark (benchmarker) {
const ipfs = await Ipfs.create({ repo: benchmarker.dir + '/ipfs' })
const { log } = await createLog(ipfs, 'A')

await appendEntries(log, height)
const values = log.values

benchmarker.startRecording()
for (const { hash } of values) {
log.has(hash)
}
benchmarker.stopRecording()

await ipfs.stop()
}

module.exports = {
benchmark
}
23 changes: 23 additions & 0 deletions benchmarks/heads.benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict'
const Ipfs = require('ipfs')
const { createLog, height, appendEntries } = require('./utils')

async function benchmark (benchmarker) {
const ipfs = await Ipfs.create({ repo: benchmarker.dir + '/ipfs' })
const { log } = await createLog(ipfs, 'A')

await appendEntries(log, height)

const cycle = () => log.heads
benchmarker.startRecording()
for (let i = 0; i < height; i++) {
cycle()
}
benchmarker.stopRecording()

await ipfs.stop()
}

module.exports = {
benchmark
}
24 changes: 24 additions & 0 deletions benchmarks/join.benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict'
const Ipfs = require('ipfs')
const { createLog, height } = require('./utils')

async function benchmark (benchmarker) {
const ipfs = await Ipfs.create({ repo: benchmarker.dir + '/ipfs' })
const { log: logA } = await createLog(ipfs, 'A')
const { log: logB } = await createLog(ipfs, 'B')

benchmarker.trackMemory()
benchmarker.startRecording()
for (let i = 0; i < height; i++) {
const now = Date.now()
await Promise.all([logA.append(now), logB.append(now)])
await Promise.all([logA.join(logB), logB.join(logA)])
}
benchmarker.stopRecording()

await ipfs.stop()
}

module.exports = {
benchmark
}
23 changes: 23 additions & 0 deletions benchmarks/tail-hashes.benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict'
const Ipfs = require('ipfs')
const { createLog, height, appendEntries } = require('./utils')

async function benchmark (benchmarker) {
const ipfs = await Ipfs.create({ repo: benchmarker.dir + '/ipfs' })
const { log } = await createLog(ipfs, 'A')

await appendEntries(height)

const cycle = () => log.tailHashes
benchmarker.startRecording()
for (let i = 0; i < height; i++) {
cycle()
}
benchmarker.stopRecording()

await ipfs.stop()
}

module.exports = {
benchmark
}
23 changes: 23 additions & 0 deletions benchmarks/tails.benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict'
const Ipfs = require('ipfs')
const { createLog, height, appendEntries } = require('./utils')

async function benchmark (benchmarker) {
const ipfs = await Ipfs.create({ repo: benchmarker.dir + '/ipfs' })
const { log } = await createLog(ipfs, 'A')

await appendEntries(height)

const cycle = () => log.tails
benchmarker.startRecording()
for (let i = 0; i < height; i++) {
cycle()
}
benchmarker.stopRecording()

await ipfs.stop()
}

module.exports = {
benchmark
}
23 changes: 23 additions & 0 deletions benchmarks/traverse.benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict'
const Ipfs = require('ipfs')
const { createLog, height, appendEntries } = require('./utils')

async function benchmark (benchmarker) {
const ipfs = await Ipfs.create({ repo: benchmarker.dir + '/ipfs' })
const { log } = await createLog(ipfs, 'A')

await appendEntries(height)

const cycle = () => log.traverse(log.heads)
benchmarker.startRecording()
for (let i = 0; i < height; i++) {
cycle()
}
benchmarker.stopRecording()

await ipfs.stop()
}

module.exports = {
benchmark
}
4 changes: 2 additions & 2 deletions benchmarks/utils/create-log.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const Keystore = require('orbit-db-keystore')
const IdentityProvider = require('orbit-db-identity-provider')
const leveldown = require('leveldown')
const storage = require('orbit-db-storage-adapter')(leveldown)
const level = require('level')
const storage = require('orbit-db-storage-adapter')(level)

const Log = require('../../src/log')
const AccessController = Log.AccessController
Expand Down
15 changes: 15 additions & 0 deletions benchmarks/utils/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict'
const appendEntries = async (log, height, { refCount, withEntries } = {}) => {
const entries = []
for (let i = 0; i < height; i++) {
const entry = await log.append(Date.now(), refCount)
if (withEntries) entries.push(entry)
}
return { entries }
}

module.exports = {
createLog: require('./create-log'),
height: 5000,
appendEntries
}
23 changes: 23 additions & 0 deletions benchmarks/values.benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict'
const Ipfs = require('ipfs')
const { createLog, height, appendEntries } = require('./utils')

async function benchmark (benchmarker) {
const ipfs = await Ipfs.create({ repo: benchmarker.dir + '/ipfs' })
const { log } = await createLog(ipfs, 'A')

await appendEntries(height)

const cycle = () => log.values
benchmarker.startRecording()
for (let i = 0; i < height; i++) {
cycle()
}
benchmarker.stopRecording()

await ipfs.stop()
}

module.exports = {
benchmark
}
Loading