-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench.text.editor.js
72 lines (62 loc) · 2.07 KB
/
bench.text.editor.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
let Benchmark = require('benchmark')
let suite = new Benchmark.Suite('Couting words')
const chalk = require('chalk')
console.log('------ prepare data')
const STR = '1 2 5 3 6 4'
function processData (input) {
//Enter your code here
}
return;
// add tests
suite
.add('get max number using array.reduce and Math.max', function () {
/**
size_t getHeight(const binary_tree_t *tree)
{
size_t r, l, height = 0;
if (tree)
{
r = tree->right ? getHeight(tree->right) + 1 : 0;
l = tree->left ? getHeight(tree->left) + 1 : 0;
height += (r > l ? r : l);
}
return (height);
}
*/
function getHeight (root) {
console.log(root)
let right = 0
let left = 0
let height = 0
if (root) {
right = root.right ? getHeight(root.right) + 1 : 0
left = root.lefy ? getHeight(root.left) + 1 : 0
height += right > left ? right : left
}
console.log('-----------')
return height
}
getHeight(tree)
})
// add listeners
.on('cycle', function (event) {
console.log(chalk.magenta(String(event.target)))
})
.on('complete', function () {
// console.log(this.filter('fastest'))
const fastest = this.filter('fastest')
console.log(chalk.green('Fastest is ' + fastest.map('name')))
function compare(a, b) {
if (a > b)
return (a / b * 100).toFixed() + '% faster';
if (a == b)
return "the same";
return (b / a * 100).toFixed() + '% slower';
}
console.log(chalk.blue(`get max number using simple for statement is ${compare(fastest.map('hz'), this[0].hz)} than ${this[0].name}`));
console.log(chalk.blue(`get max number using simple for statement is ${compare(fastest.map('hz'), this[1].hz)} than ${this[1].name}`));
})
// run async
.run({
async: true
})