Skip to content

Commit 0b195dc

Browse files
committed
Document benchmarks, clearer output
1 parent 2464b53 commit 0b195dc

32 files changed

+347
-33
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# node-tar
22

3-
Tar for Node.js.
3+
[Fast](./benchmarks) and full-featured Tar for Node.js
44

5-
Designed to mimic the behavior of `tar(1)` on unix systems. If you
6-
are familiar with how tar works, most of this will hopefully be
5+
The API is designed to mimic the behavior of `tar(1)` on unix systems.
6+
If you are familiar with how tar works, most of this will hopefully be
77
straightforward for you. If not, then hopefully this module can teach
88
you useful unix skills that may come in handy someday :)
99

benchmarks/README.md

Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
# node-tar benchmarks
2+
3+
There are a bunch of benchmark scripts in `./benchmarks`. These
4+
compare the various ways to use node-tar, tar-fs, tar-stream, and the
5+
fstream version of node-tar.
6+
7+
You can pass a filename to all the parse and extract benchmarks, and a
8+
folder to the create benchmark.
9+
10+
```
11+
$ time tar cf downloads.tar -C ~ Downloads
12+
13+
real 0m23.751s
14+
user 0m0.630s
15+
sys 0m11.743s
16+
17+
$ node benchmarks/create/old-async.js ~/Downloads
18+
42272.452728 (42.3s)
19+
20+
$ node benchmarks/create/tar-fs-async.js ~/Downloads
21+
25599.186971 (25.6s)
22+
23+
$ node benchmarks/create/node-tar-file-sync.js ~/Downloads
24+
23677.560389 (23.7s)
25+
26+
$ node benchmarks/extract/old-async.js downloads.tar
27+
214248.237973 (214.2s)
28+
29+
$ node benchmarks/extract/tar-fs-async.js downloads.tar
30+
33976.501071 (34.0s)
31+
32+
$ node benchmarks/extract/node-tar-file-sync.js downloads.tar
33+
17254.956028 (17.3s)
34+
```
35+
36+
To run a bunch of benchmarks, type `npm run bench`.
37+
38+
```
39+
$ npm run bench
40+
41+
> [email protected] bench /Users/isaacs/dev/js/tar
42+
> for i in benchmarks/*/*.js; do echo $i; for j in {1..5}; do node $i || break; done; done
43+
44+
benchmarks/create/node-tar-file-async.js
45+
118.153
46+
124.152
47+
117.554
48+
111.221
49+
108.186
50+
benchmarks/create/node-tar-file-sync.js
51+
93.476
52+
93.019
53+
99.313
54+
94.475
55+
89.388
56+
benchmarks/create/node-tar-stream-async.js
57+
109.041
58+
109.456
59+
122.198
60+
108.559
61+
108.101
62+
benchmarks/create/node-tar-stream-sync.js
63+
95.449
64+
100.572
65+
122.602
66+
94.681
67+
95.732
68+
benchmarks/create/old-async.js
69+
285.111
70+
254.173
71+
255.68
72+
270.314
73+
322.798
74+
benchmarks/create/pack-async.js
75+
129.29
76+
134.56
77+
98.538
78+
108.607
79+
120.551
80+
benchmarks/create/pack-sync.js
81+
100.473
82+
98.25
83+
98.448
84+
96.355
85+
93.235
86+
benchmarks/create/tar-fs-async.js
87+
166.825
88+
205.416
89+
168.769
90+
172.992
91+
189.854
92+
benchmarks/extract/node-tar-file-async.js
93+
1228.391 (1.2s)
94+
985.846
95+
1072.73 (1.1s)
96+
859.067
97+
881.437
98+
benchmarks/extract/node-tar-file-sync.js
99+
1215.858 (1.2s)
100+
1086.313 (1.1s)
101+
1132.42 (1.1s)
102+
1076.573 (1.1s)
103+
1188.361 (1.2s)
104+
benchmarks/extract/node-tar-stream-async.js
105+
1035.188
106+
1061.6 (1.1s)
107+
956.506
108+
1103.758 (1.1s)
109+
1186.414 (1.2s)
110+
benchmarks/extract/node-tar-stream-sync.js
111+
1282.724 (1.3s)
112+
1470.698 (1.5s)
113+
1080.566 (1.1s)
114+
1351.072 (1.4s)
115+
1149.005 (1.1s)
116+
benchmarks/extract/old-async.js
117+
2697.997 (2.7s)
118+
2638.7 (2.6s)
119+
2676.483 (2.7s)
120+
2456.808 (2.5s)
121+
2632.987 (2.6s)
122+
benchmarks/extract/old-sync.js
123+
2630.631 (2.6s)
124+
3348.535 (3.3s)
125+
2804.793 (2.8s)
126+
2683.767 (2.7s)
127+
2429.574 (2.4s)
128+
benchmarks/extract/tar-fs-async.js
129+
3476.535 (3.5s)
130+
3295.247 (3.3s)
131+
3649.666 (3.6s)
132+
2990.234 (3s)
133+
3080.088 (3.1s)
134+
benchmarks/extract/tar-fs-sync.js
135+
2912.93 (2.9s)
136+
2906.809 (2.9s)
137+
2895.982 (2.9s)
138+
2788.321 (2.8s)
139+
2763.063 (2.8s)
140+
benchmarks/extract/unpack-async.js
141+
917.924
142+
996.596
143+
980.011
144+
959.166
145+
912.224
146+
benchmarks/extract/unpack-sync.js
147+
1086.979 (1.1s)
148+
1003.369
149+
1007.736
150+
1014.644
151+
965.837
152+
benchmarks/parse/fast-scan-no-body.js
153+
97.161
154+
96.942
155+
92.594
156+
83.1
157+
83.687
158+
benchmarks/parse/fast-scan.js
159+
103.901
160+
99.561
161+
110.304
162+
121.186
163+
108.992
164+
benchmarks/parse/node-tar-file-async.js
165+
142.502
166+
140.748
167+
150.195
168+
139.453
169+
138.621
170+
benchmarks/parse/node-tar-file-sync.js
171+
127.851
172+
125.472
173+
126.201
174+
128.51
175+
125.533
176+
benchmarks/parse/node-tar-stream-async.js
177+
143.174
178+
155.308
179+
148.667
180+
143.529
181+
150.993
182+
benchmarks/parse/node-tar-stream-sync.js
183+
142.549
184+
141.47
185+
135.668
186+
133.812
187+
126.849
188+
benchmarks/parse/old-async.js
189+
170.105
190+
146.608
191+
148.354
192+
155.255
193+
175.018
194+
benchmarks/parse/old-sync.js
195+
126.975
196+
125.584
197+
126.011
198+
128.157
199+
126.623
200+
benchmarks/parse/parse-async.js
201+
164.151
202+
145.304
203+
160.246
204+
148.458
205+
224.993
206+
benchmarks/parse/parse-sync.js
207+
125.92
208+
142.842
209+
115.224
210+
116.128
211+
119.958
212+
benchmarks/parse/tar-stream-async.js
213+
157.796
214+
143.333
215+
143.042
216+
149.831
217+
147.184
218+
benchmarks/parse/tar-stream-sync.js
219+
126.07
220+
120.343
221+
125.797
222+
116.791
223+
126.587
224+
```

benchmarks/create/node-tar-file-async.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@ tar.c({
1111
cwd: cwd
1212
}, ['']).then(_ => {
1313
const end = process.hrtime(start)
14-
console.error(end[0]*1e3 + end[1]/1e6)
14+
const ms = Math.round(end[0]*1e6 + end[1]/1e3)/1e3
15+
const s = Math.round(end[0]*10 + end[1]/1e8)/10
16+
const ss = s <= 1 ? '' : ' (' + s + 's)'
17+
console.error('%d%s', ms, ss)
1518
})

benchmarks/create/node-tar-file-sync.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ tar.c({
1313
}, [''])
1414

1515
const end = process.hrtime(start)
16-
console.error(end[0]*1e3 + end[1]/1e6)
16+
const ms = Math.round(end[0]*1e6 + end[1]/1e3)/1e3
17+
const s = Math.round(end[0]*10 + end[1]/1e8)/10
18+
const ss = s <= 1 ? '' : ' (' + s + 's)'
19+
console.error('%d%s', ms, ss)

benchmarks/create/node-tar-stream-async.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@ const start = process.hrtime()
99
const c = tar.c({ cwd: cwd }, [''])
1010
c.pipe(fs.createWriteStream(file)).on('close', _ => {
1111
const end = process.hrtime(start)
12-
console.error(end[0]*1e3 + end[1]/1e6)
12+
const ms = Math.round(end[0]*1e6 + end[1]/1e3)/1e3
13+
const s = Math.round(end[0]*10 + end[1]/1e8)/10
14+
const ss = s <= 1 ? '' : ' (' + s + 's)'
15+
console.error('%d%s', ms, ss)
1316
})

benchmarks/create/node-tar-stream-sync.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ const start = process.hrtime()
99
const c = tar.c({ cwd: cwd, sync: true }, [''])
1010
fs.writeFileSync(file, c.read())
1111
const end = process.hrtime(start)
12-
console.error(end[0]*1e3 + end[1]/1e6)
12+
const ms = Math.round(end[0]*1e6 + end[1]/1e3)/1e3
13+
const s = Math.round(end[0]*10 + end[1]/1e8)/10
14+
const ss = s <= 1 ? '' : ' (' + s + 's)'
15+
console.error('%d%s', ms, ss)

benchmarks/create/old-async.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@ const fstr = fs.createWriteStream(file)
1313
d.pipe(p).pipe(fstr)
1414
fstr.on('close', _ => {
1515
const end = process.hrtime(start)
16-
console.error(end[0]*1e3 + end[1]/1e6)
16+
const ms = Math.round(end[0]*1e6 + end[1]/1e3)/1e3
17+
const s = Math.round(end[0]*10 + end[1]/1e8)/10
18+
const ss = s <= 1 ? '' : ' (' + s + 's)'
19+
console.error('%d%s', ms, ss)
1720
})

benchmarks/create/pack-async.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@ const p = new Pack({ cwd: cwd })
1010
p.add('').end()
1111
p.pipe(fs.createWriteStream(file)).on('finish', _ => {
1212
const end = process.hrtime(start)
13-
console.error(end[0]*1e3 + end[1]/1e6)
13+
const ms = Math.round(end[0]*1e6 + end[1]/1e3)/1e3
14+
const s = Math.round(end[0]*10 + end[1]/1e8)/10
15+
const ss = s <= 1 ? '' : ' (' + s + 's)'
16+
console.error('%d%s', ms, ss)
1417
})

benchmarks/create/pack-sync.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ const p = new Pack.Sync({ cwd: cwd })
1010
p.add('')
1111
fs.writeFileSync(file, p.read())
1212
const end = process.hrtime(start)
13-
console.error(end[0]*1e3 + end[1]/1e6)
13+
const ms = Math.round(end[0]*1e6 + end[1]/1e3)/1e3
14+
const s = Math.round(end[0]*10 + end[1]/1e8)/10
15+
const ss = s <= 1 ? '' : ' (' + s + 's)'
16+
console.error('%d%s', ms, ss)

benchmarks/create/tar-fs-async.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@ const tar = require('tar-fs')
99
const p = tar.pack(cwd)
1010
p.pipe(fs.createWriteStream(file)).on('close', _ => {
1111
const end = process.hrtime(start)
12-
console.log(end[0]*1e3 + end[1]/1e6)
12+
const ms = Math.round(end[0]*1e6 + end[1]/1e3)/1e3
13+
const s = Math.round(end[0]*10 + end[1]/1e8)/10
14+
const ss = s <= 1 ? '' : ' (' + s + 's)'
15+
console.error('%d%s', ms, ss)
1316
})

benchmarks/extract/node-tar-file-async.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@ tar.x({
1313
cwd: cwd
1414
}).then(_ => {
1515
const end = process.hrtime(start)
16-
console.error(end[0]*1e3 + end[1]/1e6)
16+
const ms = Math.round(end[0]*1e6 + end[1]/1e3)/1e3
17+
const s = Math.round(end[0]*10 + end[1]/1e8)/10
18+
const ss = s <= 1 ? '' : ' (' + s + 's)'
19+
console.error('%d%s', ms, ss)
1720
})

benchmarks/extract/node-tar-file-sync.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@ tar.x({
1515
})
1616

1717
const end = process.hrtime(start)
18-
console.error(end[0]*1e3 + end[1]/1e6)
18+
const ms = Math.round(end[0]*1e6 + end[1]/1e3)/1e3
19+
const s = Math.round(end[0]*10 + end[1]/1e8)/10
20+
const ss = s <= 1 ? '' : ' (' + s + 's)'
21+
console.error('%d%s', ms, ss)

benchmarks/extract/node-tar-stream-async.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ const start = process.hrtime()
1212
const x = tar.x({ cwd: cwd })
1313
x.on('end', _ => {
1414
const end = process.hrtime(start)
15-
console.error(end[0]*1e3 + end[1]/1e6)
15+
const ms = Math.round(end[0]*1e6 + end[1]/1e3)/1e3
16+
const s = Math.round(end[0]*10 + end[1]/1e8)/10
17+
const ss = s <= 1 ? '' : ' (' + s + 's)'
18+
console.error('%d%s', ms, ss)
1619
})
1720
fs.createReadStream(file).pipe(x)

benchmarks/extract/node-tar-stream-sync.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ const start = process.hrtime()
1212
const x = tar.x({ sync: true, cwd: cwd })
1313
x.on('end', _ => {
1414
const end = process.hrtime(start)
15-
console.error(end[0]*1e3 + end[1]/1e6)
15+
const ms = Math.round(end[0]*1e6 + end[1]/1e3)/1e3
16+
const s = Math.round(end[0]*10 + end[1]/1e8)/10
17+
const ss = s <= 1 ? '' : ' (' + s + 's)'
18+
console.error('%d%s', ms, ss)
1619
})
1720
x.end(fs.readFileSync(file))

benchmarks/extract/old-async.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ const x = new Extract({ path: cwd })
1313
x.on('entry', entry => entry.resume())
1414
x.on('close', _ => {
1515
const end = process.hrtime(start)
16-
console.error(end[0]*1e3 + end[1]/1e6)
16+
const ms = Math.round(end[0]*1e6 + end[1]/1e3)/1e3
17+
const s = Math.round(end[0]*10 + end[1]/1e8)/10
18+
const ss = s <= 1 ? '' : ' (' + s + 's)'
19+
console.error('%d%s', ms, ss)
1720
})
1821
fs.createReadStream(file).pipe(x)

benchmarks/extract/old-sync.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ const x = new Extract({ path: cwd })
1414
x.on('entry', entry => entry.resume())
1515
x.on('close', _ => {
1616
const end = process.hrtime(start)
17-
console.error(end[0]*1e3 + end[1]/1e6)
17+
const ms = Math.round(end[0]*1e6 + end[1]/1e3)/1e3
18+
const s = Math.round(end[0]*10 + end[1]/1e8)/10
19+
const ss = s <= 1 ? '' : ' (' + s + 's)'
20+
console.error('%d%s', ms, ss)
1821
})
1922
x.end(data)

benchmarks/extract/tar-fs-async.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ const start = process.hrtime()
1212
const e = tar.extract(cwd)
1313
process.on('exit', (code, signal) => {
1414
const end = process.hrtime(start)
15-
console.log(end[0]*1e3 + end[1]/1e6)
15+
const ms = Math.round(end[0]*1e6 + end[1]/1e3)/1e3
16+
const s = Math.round(end[0]*10 + end[1]/1e8)/10
17+
const ss = s <= 1 ? '' : ' (' + s + 's)'
18+
console.error('%d%s', ms, ss)
1619
})
1720
fs.createReadStream(file).pipe(e)

benchmarks/extract/tar-fs-sync.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ const start = process.hrtime()
1414
const e = tar.extract(cwd)
1515
process.on('exit', (code, signal) => {
1616
const end = process.hrtime(start)
17-
console.log(end[0]*1e3 + end[1]/1e6)
17+
const ms = Math.round(end[0]*1e6 + end[1]/1e3)/1e3
18+
const s = Math.round(end[0]*10 + end[1]/1e8)/10
19+
const ss = s <= 1 ? '' : ' (' + s + 's)'
20+
console.error('%d%s', ms, ss)
1821
})
1922
e.end(data)

0 commit comments

Comments
 (0)