Skip to content

Commit 9597e42

Browse files
update readme + files
1 parent 9604e3c commit 9597e42

File tree

5 files changed

+23
-15
lines changed

5 files changed

+23
-15
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ jspm_packages
1919
*.tgz
2020
.yarn-integrity
2121
.idea
22+
perf.data*

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ console.log(decode('d3:abcli13eee')) // {abc: [ 13 ]}
2020
*nodejs 22 / ubuntu 22 / i5 4690*
2121

2222
```
23-
┌────────────────┬──────────────────┬───────────────────┬────────────────────────┬────────────────────────┬─────────┐
24-
│ Task name │ Latency avg (ns) │ Latency med (ns) │ Throughput avg (ops/s) │ Throughput med (ops/s) │ Samples │
25-
├────────────────┼──────────────────┼───────────────────┼────────────────────────┼────────────────────────┼─────────┤
26-
│ 'bencode' │ '12449 ± 4.47%' │ '9560.5 ± 505.50' │ '96067 ± 0.51%' │ '104597 ± 5675' │ 8034
27-
│ 'btparse' │ '4379.3 ± 1.50%' │ '3921.0 ± 41.00' │ '243364 ± 0.17%' │ '255037 ± 2695' │ 26886
28-
│ 'btparse#lazy' │ '3369.0 ± 2.97%' │ '3143.0 ± 40.00' │ '311258 ± 0.07%' │ '318167 ± 4101' │ 33297
29-
└────────────────┴──────────────────┴───────────────────┴────────────────────────┴────────────────────────┴─────────┘
23+
┌─────────┬────────────────┬──────────────────┬───────────────────┬────────────────────────┬────────────────────────┬─────────┐
24+
(index) │ Task name │ Latency avg (ns) │ Latency med (ns) │ Throughput avg (ops/s) │ Throughput med (ops/s) │ Samples │
25+
├─────────┼────────────────┼──────────────────┼───────────────────┼────────────────────────┼────────────────────────┼─────────┤
26+
0 │ 'bencode' │ '11039 ± 0.92%' │ '9280.0 ± 254.00' │ '101444 ± 0.13%' │ '107759 ± 2971' │ 72468
27+
1 │ 'btparse' │ '3709.3 ± 0.73%' │ '3467.0 ± 43.00' │ '281595 ± 0.04%' │ '288434 ± 3537' │ 215675
28+
2 │ 'btparse#lazy' │ '3335.1 ± 0.50%' │ '3113.0 ± 45.00' │ '313420 ± 0.03%' │ '321234 ± 4678' │ 239876
29+
└─────────┴────────────────┴──────────────────┴───────────────────┴────────────────────────┴────────────────────────┴─────────┘
3030
```
3131
## API
3232

bench/decode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import btparse from '../index.js';
66
import lazybtparse from '../lazy.js';
77

88
const file = fs.readFileSync(path.join(import.meta.dirname, 'test.torrent'));
9-
const bench = new Bench({ name: 'torrent parsers bench', time: 100 });
9+
const bench = new Bench({ name: 'torrent parsers bench', time: 800 });
1010

1111
bench
1212
.add('bencode', () => bencode.decode(file))

bench/perf.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ import bencode from 'bencode';
44
import btparse from '../index.js';
55
import lazybtparse from '../lazy.js';
66

7+
/**
8+
* Start profiler
9+
* sudo perf record -g -- node --perf-basic-prof ./bench/perf.js
10+
* Show data
11+
* sudo perf report --no-children
12+
* How to
13+
* https://habr.com/ru/articles/350018/
14+
*/
15+
716
const file = fs.readFileSync(path.join(import.meta.dirname, 'test.torrent'));
817
const time = 1e5;
918

example.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
'use strict'
1+
import * as fs from 'node:fs';
2+
import path from 'node:path';
23

3-
const fs = require('fs')
4-
const path = require('path')
4+
import decode from './index.js';
55

6-
const lazybtparse = require('./lazy')
6+
const file = fs.readFileSync(path.join(import.meta.dirname, 'bench/test.torrent'))
77

8-
const file = fs.readFileSync(path.join(__dirname, 'bench/test.torrent'))
9-
10-
console.log(lazybtparse(file).info.pieces)
8+
console.log(decode(file).info.pieces);

0 commit comments

Comments
 (0)