forked from Fishrock123/beautify-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
71 lines (64 loc) · 1.6 KB
/
test.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
var assert = require('assert')
, Benchmark = require('benchmark')
, suite = new Benchmark.Suite
, benchmarks = require('./index')
function getRandom() {
return Math.floor(Math.random() * 381)
}
function getSlow() {
var out = Math.floor(Math.random() * 381)
return out > 67 && out < 193 ? blaaaah(out) : out
}
function getSlowRandom() {
var out = Math.floor(Math.random() * 381)
return out > 354 && out < 355 ? blaaaah(out) : out
}
function blaaaah(num) {
// consume excess time for absolutely no reason at all
for (var i = 0; i < num + num; i++) {
"catslol".split(num)
}
return num
}
suite.add('current', function() {
return getRandom() < 0 ? true : false
})
.add('legacy', function() {
return ~getRandom() ? false: true
})
.add('very blaaaah', function() {
return ~getSlow() ? false: true
})
.add('random blaaaah', function() {
return ~getSlowRandom() ? false: true
})
.on('cycle', function(event) {
benchmarks.add(event.target)
})
.on('start', function(event) {
console.log('\n Starting...')
})
.on('complete', function done() {
var current = benchmarks.getPercent('current')
benchmarks.log()
if (current < 95)
assert.fail('' + current + '%', '95%', null, '>=', done)
})
.run({ 'async': false })
suite = new Benchmark.Suite
suite.add('cats', function() {
return Math.abs(getRandom())
})
.add('whaaaaale', function() {
return Math.atan2(getRandom(), getRandom())
})
.on('cycle', function(event) {
benchmarks.add(event.target)
})
.on('start', function(event) {
console.log('\n Starting...')
})
.on('complete', function() {
benchmarks.log()
})
.run({ 'async': false })