arnaucube
arnaucube/thoughtsPublic Self-hosted repository
thoughts/node_modules/mongoose/node_modules/sliced/bench.js
node_modules/mongoose/node_modules/sliced/bench.jsRaw
 1
 2var sliced = require('./')
 3var Bench = require('benchmark');
 4var s = new Bench.Suite;
 5var slice = [].slice;
 6
 7s.add('Array.prototype.slice.call', function () {
 8  Array.prototype.slice.call(arguments);
 9}).add('[].slice.call', function () {
10  [].slice.call(arguments);
11}).add('cached slice.call', function () {
12  slice.call(arguments)
13}).add('sliced', function () {
14  sliced(arguments)
15}).on('cycle', function (evt) {
16  console.log(String(evt.target));
17}).on('complete', function () {
18  console.log('fastest is %s', this.filter('fastest').pluck('name'));
19})
20.run();
21
22var s = new Bench.Suite;
23s.add('Array.prototype.slice.call(arguments, 1)', function () {
24  Array.prototype.slice.call(arguments, 1);
25}).add('[].slice.call(arguments, 1)', function () {
26  [].slice.call(arguments, 1);
27}).add('cached slice.call(arguments, 1)', function () {
28  slice.call(arguments, 1)
29}).add('sliced(arguments, 1)', function () {
30  sliced(arguments, 1)
31}).on('cycle', function (evt) {
32  console.log(String(evt.target));
33}).on('complete', function () {
34  console.log('fastest is %s', this.filter('fastest').pluck('name'));
35})
36.run();
37
38var s = new Bench.Suite;
39s.add('Array.prototype.slice.call(arguments, -1)', function () {
40  Array.prototype.slice.call(arguments, -1);
41}).add('[].slice.call(arguments, -1)', function () {
42  [].slice.call(arguments, -1);
43}).add('cached slice.call(arguments, -1)', function () {
44  slice.call(arguments, -1)
45}).add('sliced(arguments, -1)', function () {
46  sliced(arguments, -1)
47}).on('cycle', function (evt) {
48  console.log(String(evt.target));
49}).on('complete', function () {
50  console.log('fastest is %s', this.filter('fastest').pluck('name'));
51})
52.run();
53
54var s = new Bench.Suite;
55s.add('Array.prototype.slice.call(arguments, -2, -10)', function () {
56  Array.prototype.slice.call(arguments, -2, -10);
57}).add('[].slice.call(arguments, -2, -10)', function () {
58  [].slice.call(arguments, -2, -10);
59}).add('cached slice.call(arguments, -2, -10)', function () {
60  slice.call(arguments, -2, -10)
61}).add('sliced(arguments, -2, -10)', function () {
62  sliced(arguments, -2, -10)
63}).on('cycle', function (evt) {
64  console.log(String(evt.target));
65}).on('complete', function () {
66  console.log('fastest is %s', this.filter('fastest').pluck('name'));
67})
68.run();
69
70var s = new Bench.Suite;
71s.add('Array.prototype.slice.call(arguments, -2, -1)', function () {
72  Array.prototype.slice.call(arguments, -2, -1);
73}).add('[].slice.call(arguments, -2, -1)', function () {
74  [].slice.call(arguments, -2, -1);
75}).add('cached slice.call(arguments, -2, -1)', function () {
76  slice.call(arguments, -2, -1)
77}).add('sliced(arguments, -2, -1)', function () {
78  sliced(arguments, -2, -1)
79}).on('cycle', function (evt) {
80  console.log(String(evt.target));
81}).on('complete', function () {
82  console.log('fastest is %s', this.filter('fastest').pluck('name'));
83})
84.run();
85
86/**
87 * Output:
88 *
89 * Array.prototype.slice.call x 1,289,592 ops/sec ±2.88% (87 runs sampled)
90 * [].slice.call x 1,345,451 ops/sec ±1.68% (97 runs sampled)
91 * cached slice.call x 10,719,886 ops/sec ±1.04% (99 runs sampled)
92 * sliced x 15,809,545 ops/sec ±1.46% (93 runs sampled)
93 * fastest is sliced
94 *
95 */