-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbench.js
More file actions
39 lines (34 loc) · 1.2 KB
/
bench.js
File metadata and controls
39 lines (34 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const Benchmark = require('benchmark');
const colurs = require('colurs').init();
const bench = new Benchmark.Suite;
const Tabler = require('./dist').Tabler;
const tabler = new Tabler();
const ui = require('cliui')();
const rows = [
[{ text: 'one' }, { text: 'two' }, { text: 'three' }],
[{ text: 'one' }, { text: 'two' }, { text: 'three' }],
[{ text: 'one' }, { text: 'two' }, { text: 'three' }],
[{ text: 'one' }, { text: 'two' }, { text: 'three' }],
[{ text: 'one' }, { text: 'two' }, { text: 'three' }]
];
console.log('\n' + colurs.underline('Benchmark Starting...') + '\n');
bench.add('Tabler', function() {
tabler.rows(rows);
tabler.render();
})
.add('Yargs Cliui', function() {
rows.forEach(r => ui.div(r));
ui.toString();
})
.on('cycle', function(event) {
const t = event.target;
let result = String(t);
console.log(colurs.dim(result));
})
.on('complete', function() {
console.log('\n' + colurs.underline('Results:') + '\n');
const fastest = this.filter('fastest').map('name');
console.log(colurs.bold.greenBright(fastest[0]) + ' (fastest)\n' + colurs.dim.redBright(fastest[1]) + ' (slowest)');
console.log();
})
.run({ 'async': false });