Skip to content
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
26 changes: 26 additions & 0 deletions benchmarks/operations/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# multiaddr Benchmark

Benchmarks multiaddr performance during common operations - parsing strings,
encapsulating/decapsulating addresses, turning to bytes, decoding bytes, etc.

## Running the benchmarks

```console
% npm start

> [email protected] start
> npm run build && node dist/src/index.js


> [email protected] build
> aegir build --bundle false

[06:10:56] tsc [started]
[06:10:56] tsc [completed]
┌─────────┬─────────────────────────────────────────┬──────────────┬────────┬───────┬────────┐
│ (index) │ Implementation │ ops/s │ ms/op │ runs │ p99 │
├─────────┼─────────────────────────────────────────┼──────────────┼────────┼───────┼────────┤
│ 0 │ 'head' │ '2427997.80' │ '0.00' │ 50000 │ '0.00' │
│ 1 │ '@multiformats/multiaddr-matcher-1.7.2' │ '1098132.24' │ '0.00' │ 50000 │ '0.00' │
└─────────┴─────────────────────────────────────────┴──────────────┴────────┴───────┴────────┘
```
21 changes: 21 additions & 0 deletions benchmarks/operations/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "benchmarks-operations",
"version": "1.0.0",
"main": "index.js",
"private": true,
"type": "module",
"scripts": {
"clean": "aegir clean",
"build": "aegir build --bundle false",
"lint": "aegir lint",
"dep-check": "aegir dep-check",
"doc-check": "aegir doc-check",
"start": "npm run build && node dist/test/index.js"
},
"devDependencies": {
"@multiformats/multiaddr-matcher-1.7.2": "npm:@multiformats/[email protected]",
"@multiformats/multiaddr-matcher": "../../",
"aegir": "^47.0.7",
"tinybench": "^4.0.1"
}
}
1 change: 1 addition & 0 deletions benchmarks/operations/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {}
58 changes: 58 additions & 0 deletions benchmarks/operations/test/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* eslint-disable no-console */

import { multiaddr } from '@multiformats/multiaddr'
import { TCP } from '@multiformats/multiaddr-matcher'
import { TCP as TCP_172 } from '@multiformats/multiaddr-matcher-1.7.2'
import { Bench } from 'tinybench'

const ITERATIONS = parseInt(process.env.ITERATIONS ?? '50000')
const MIN_TIME = parseInt(process.env.MIN_TIME ?? '1')
const RESULT_PRECISION = 2

function bench (m: typeof TCP | typeof TCP_172): void {
const ma = multiaddr('/ip4/127.0.0.1/tcp/1234')

m.exactMatch(ma)
}

async function main (): Promise<void> {
const suite = new Bench({
iterations: ITERATIONS,
time: MIN_TIME
})
suite.add('head', () => {
bench(TCP)
})
suite.add('@multiformats/multiaddr-matcher-1.7.2', () => {
bench(TCP_172)
})

await suite.run()

console.table(suite.tasks.map(({ name, result }) => {
if (result?.error != null) {
console.error(result.error)

return {
Implementation: name,
'ops/s': 'error',
'ms/op': 'error',
runs: 'error',
p99: 'error'
}
}

return {
Implementation: name,
'ops/s': result?.hz.toFixed(RESULT_PRECISION),
'ms/op': result?.period.toFixed(RESULT_PRECISION),
runs: result?.samples.length,
p99: result?.p99.toFixed(RESULT_PRECISION)
}
}))
}

main().catch(err => {
console.error(err)
process.exit(1)
})
15 changes: 15 additions & 0 deletions benchmarks/operations/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "aegir/src/config/tsconfig.aegir.json",
"compilerOptions": {
"outDir": "dist"
},
"include": [
"src",
"test"
],
"references": [
{
"path": "../../"
}
]
}
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,7 @@
"docs": "aegir docs"
},
"dependencies": {
"@chainsafe/is-ip": "^2.0.1",
"@multiformats/multiaddr": "^12.0.0",
"multiformats": "^13.0.0"
"@multiformats/multiaddr": "^12.0.0"
},
"devDependencies": {
"aegir": "^47.0.19"
Expand Down
Loading