-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy patharguments.js
55 lines (41 loc) · 933 Bytes
/
arguments.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
'use strict'
var benchmark = require('benchmark')
var suite = new benchmark.Suite()
function leakyArguments () {
return other(arguments)
}
function copyArgs () {
var array = new Array(arguments.length)
for (var i = 0; i < array.length; i++) {
array[i] = arguments[i]
}
return other(array)
}
function sliceArguments () {
var array = Array.prototype.slice.apply(arguments)
return other(array)
}
function spreadOp(...args) {
return other(args)
}
function other (toSum) {
var total = 0
for (var i = 0; i < toSum.length; i++) {
total += toSum[i]
}
return total
}
suite.add('leaky arguments', () => {
leakyArguments(1, 2, 3)
})
suite.add('Array.prototype.slice arguments', () => {
sliceArguments(1, 2, 3)
})
suite.add('for loop copy arguments', () => {
copyArgs(1, 2, 3)
})
suite.add('spread operator', () => {
spreadOp(1, 2, 3)
})
suite.on('complete', require('./print'))
suite.run()