Skip to content

Instantly share code, notes, and snippets.

@iarna
Last active May 6, 2019 19:22
Show Gist options
  • Save iarna/acfba145e421d51c4de2cdb7faa3f309 to your computer and use it in GitHub Desktop.
Save iarna/acfba145e421d51c4de2cdb7faa3f309 to your computer and use it in GitHub Desktop.
Tar / Tar fs Benchmark

Times are off of my Linux laptop.

You can run with: ```console $ npx https://gist.github.com/acfba145e421d51c4de2cdb7faa3f309.git


With default config, using node_modules, which has 1295 files (6.6M):

```console
$ node benchmark.js
Overall Benchmarking...
        tar x 
        6.92ops/sec ±3.86% (83 runs sampled)
        tar-fs x 3.44 ops/sec ±4.76% (51 runs sampled)
Overall Successful:
        tar, tar-fs
Overall Fastest:
        tar

With my downloads folder, with 505 directories and 59,511 files (5.6G):

$ node benchmark.js
Overall Benchmarking...
        tar x 0.09 ops/sec ±1.83% (5 runs sampled)
        tar-fs x 0.05 ops/sec ±2.30% (4 runs sampled)
Overall Successful:
        tar, tar-fs
Overall Fastest:
        tar
#!/usr/bin/env node
const cursor = require('ansi')(process.stdout)
const Benchmark = require('benchmark')
const rimraf = require('rimraf').sync
const nodeTar = require('./tar.js')
const tarFs = require('./tar-fs.js')
const suite = new Benchmark.Suite({
onStart: function () {
console.log('Overall Benchmarking...')
},
onComplete: function () {
console.log('Overall Successful:\n\t' +
this.filter('successful').map('name').join(', '))
console.log('Overall Fastest:\n\t' +
this.filter('fastest').map('name').join(', '))
}
})
const onCycle = event => {
rimraf('tmp-extract')
cursor.horizontalAbsolute()
cursor.eraseLine()
cursor.write('\t' + event.target)
}
const onComplete = () => {
cursor.write('\n')
}
const tests = {
'tar': nodeTar,
'tar-fs': tarFs
}
Object.keys(tests).forEach(name => {
suite.add(name, {
maxTime: 15,
defer: true,
onCycle,
onComplete,
async fn (deferred) {
await tests[name](`${__dirname}/node_modules`)
deferred.resolve()
}
})
})
suite.run()
{
"name": "tar-bench",
"version": "1.0.0",
"bin": "benchmark.js",
"scripts": {
"start": "node benchmark.js"
},
"dependencies": {
"ansi": "^0.3.1",
"benchmark": "^2.1.4",
"rimraf": "^2.6.3",
"tar": "^4.4.8",
"tar-fs": "^2.0.0"
}
}
const tar = require('tar-fs');
module.exports = input => {
return new Promise(resolve => {
tar.pack(input).pipe(tar.extract('tmp-extract/')).on('finish', () => {
resolve()
})
})
}
const tar = require('tar');
const fs = require('fs')
module.exports = input => {
return new Promise(resolve => {
fs.mkdirSync('tmp-extract')
tar.c([input]).pipe(tar.x({cwd: 'tmp-extract/'})).on('finish', () => {
resolve()
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment