-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench.js
38 lines (34 loc) · 1.16 KB
/
bench.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
'use strict';
var Benchmark = require('benchmark')
, assert = global.assert = require('assert')
, suite = new Benchmark.Suite()
var f = global.f = function f(a, b, c) {
return a + b + c
}
Function.prototype.bindSlice = require('./bind-slice')
Function.prototype.bindConcat = require('./bind-concat')
Function.prototype.bindLoop = require('./bind-loop')
suite // native must come first
.add('Function#bind (native)', function() {
assert.equal(f.bind(null, 1, 2)(3), 6)
})
.add('Function#bind (slice)', function() {
assert.equal(f.bindSlice(null, 1, 2)(3), 6)
})
.add('Function#bind (concat)', function() {
assert.equal(f.bindConcat(null, 1, 2)(3), 6)
})
.add('Function#bind (loop)', function() {
assert.equal(f.bindLoop(null, 1, 2)(3), 6)
})
.on('cycle', function(e) {
console.log(String(e.target))
})
.on('complete', function() {
var fastest = this.filter('fastest')
console.log('Fastest is ' + fastest.pluck('name'))
var native = this[0]
console.log((fastest.pluck('hz') / native.hz).toFixed(2) + 'x as fast as ' + native.name)
assert.equal(fastest.pluck('name'), 'Function#bind (loop)')
})
.run({ async: true })