File tree Expand file tree Collapse file tree 5 files changed +23
-15
lines changed
Expand file tree Collapse file tree 5 files changed +23
-15
lines changed Original file line number Diff line number Diff line change @@ -19,3 +19,4 @@ jspm_packages
1919* .tgz
2020.yarn-integrity
2121.idea
22+ perf.data *
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ import btparse from '../index.js';
66import lazybtparse from '../lazy.js' ;
77
88const 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
1111bench
1212 . add ( 'bencode' , ( ) => bencode . decode ( file ) )
Original file line number Diff line number Diff line change @@ -4,6 +4,15 @@ import bencode from 'bencode';
44import btparse from '../index.js' ;
55import 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+
716const file = fs . readFileSync ( path . join ( import . meta. dirname , 'test.torrent' ) ) ;
817const time = 1e5 ;
918
Original file line number Diff line number Diff line change 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 ) ;
You can’t perform that action at this time.
0 commit comments