-
Notifications
You must be signed in to change notification settings - Fork 9
/
bench.js
95 lines (88 loc) · 3.09 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
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
var sliced = require('./')
var Bench = require('benchmark');
var s = new Bench.Suite;
var slice = [].slice;
s.add('Array.prototype.slice.call', function () {
Array.prototype.slice.call(arguments);
}).add('[].slice.call', function () {
[].slice.call(arguments);
}).add('cached slice.call', function () {
slice.call(arguments)
}).add('sliced', function () {
sliced(arguments)
}).on('cycle', function (evt) {
console.log(String(evt.target));
}).on('complete', function () {
console.log('fastest is %s', this.filter('fastest').pluck('name'));
})
.run();
var s = new Bench.Suite;
s.add('Array.prototype.slice.call(arguments, 1)', function () {
Array.prototype.slice.call(arguments, 1);
}).add('[].slice.call(arguments, 1)', function () {
[].slice.call(arguments, 1);
}).add('cached slice.call(arguments, 1)', function () {
slice.call(arguments, 1)
}).add('sliced(arguments, 1)', function () {
sliced(arguments, 1)
}).on('cycle', function (evt) {
console.log(String(evt.target));
}).on('complete', function () {
console.log('fastest is %s', this.filter('fastest').pluck('name'));
})
.run();
var s = new Bench.Suite;
s.add('Array.prototype.slice.call(arguments, -1)', function () {
Array.prototype.slice.call(arguments, -1);
}).add('[].slice.call(arguments, -1)', function () {
[].slice.call(arguments, -1);
}).add('cached slice.call(arguments, -1)', function () {
slice.call(arguments, -1)
}).add('sliced(arguments, -1)', function () {
sliced(arguments, -1)
}).on('cycle', function (evt) {
console.log(String(evt.target));
}).on('complete', function () {
console.log('fastest is %s', this.filter('fastest').pluck('name'));
})
.run();
var s = new Bench.Suite;
s.add('Array.prototype.slice.call(arguments, -2, -10)', function () {
Array.prototype.slice.call(arguments, -2, -10);
}).add('[].slice.call(arguments, -2, -10)', function () {
[].slice.call(arguments, -2, -10);
}).add('cached slice.call(arguments, -2, -10)', function () {
slice.call(arguments, -2, -10)
}).add('sliced(arguments, -2, -10)', function () {
sliced(arguments, -2, -10)
}).on('cycle', function (evt) {
console.log(String(evt.target));
}).on('complete', function () {
console.log('fastest is %s', this.filter('fastest').pluck('name'));
})
.run();
var s = new Bench.Suite;
s.add('Array.prototype.slice.call(arguments, -2, -1)', function () {
Array.prototype.slice.call(arguments, -2, -1);
}).add('[].slice.call(arguments, -2, -1)', function () {
[].slice.call(arguments, -2, -1);
}).add('cached slice.call(arguments, -2, -1)', function () {
slice.call(arguments, -2, -1)
}).add('sliced(arguments, -2, -1)', function () {
sliced(arguments, -2, -1)
}).on('cycle', function (evt) {
console.log(String(evt.target));
}).on('complete', function () {
console.log('fastest is %s', this.filter('fastest').pluck('name'));
})
.run();
/**
* Output:
*
* Array.prototype.slice.call x 1,289,592 ops/sec ±2.88% (87 runs sampled)
* [].slice.call x 1,345,451 ops/sec ±1.68% (97 runs sampled)
* cached slice.call x 10,719,886 ops/sec ±1.04% (99 runs sampled)
* sliced x 15,809,545 ops/sec ±1.46% (93 runs sampled)
* fastest is sliced
*
*/