OLD | NEW |
| (Empty) |
1 // Copyright 2017 the V8 project authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // This benchmark is based on the six-speed benchmark build output. | |
6 // Copyright 2014 Kevin Decker <https://github.com/kpdecker/six-speed/> | |
7 | |
8 new BenchmarkSuite('SuperSpread-ES5', [1000], [ | |
9 new Benchmark('ES5', false, false, 0, ES5), | |
10 ]); | |
11 | |
12 new BenchmarkSuite('SuperSpread-Babel', [1000], [ | |
13 new Benchmark('Babel', false, false, 0, Babel), | |
14 ]); | |
15 | |
16 new BenchmarkSuite('SuperSpread-ES6', [1000], [ | |
17 new Benchmark('ES6', false, false, 0, ES6), | |
18 ]); | |
19 | |
20 // ---------------------------------------------------------------------------- | |
21 // Benchmark: ES5 | |
22 // ---------------------------------------------------------------------------- | |
23 | |
24 function ES5() { | |
25 'use strict'; | |
26 | |
27 function Point(x, y) { | |
28 this.x = x; | |
29 this.y = y; | |
30 } | |
31 | |
32 function MyPoint() { | |
33 Point.apply(this, arguments); | |
34 } | |
35 | |
36 function makePoint(x, y) { | |
37 return new MyPoint(x, y); | |
38 } | |
39 | |
40 return makePoint(1, 2); | |
41 } | |
42 | |
43 // ---------------------------------------------------------------------------- | |
44 // Benchmark: Babel | |
45 // ---------------------------------------------------------------------------- | |
46 | |
47 function _possibleConstructorReturn(self, call) { | |
48 if (!self) { | |
49 throw new ReferenceError( | |
50 'this hasn\'t been initialised - super() hasn\'t been called'); | |
51 } | |
52 return call && (typeof call === 'object' || typeof call === 'function') ? | |
53 call : | |
54 self; | |
55 } | |
56 | |
57 function _inherits(subClass, superClass) { | |
58 if (typeof superClass !== 'function' && superClass !== null) { | |
59 throw new TypeError( | |
60 'Super expression must either be null or a function, not ' + | |
61 typeof superClass); | |
62 } | |
63 subClass.prototype = Object.create(superClass && superClass.prototype, { | |
64 constructor: { | |
65 value: subClass, | |
66 enumerable: false, | |
67 writable: true, | |
68 configurable: true | |
69 } | |
70 }); | |
71 if (superClass) | |
72 Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : | |
73 subClass.__proto__ = superClass; | |
74 } | |
75 | |
76 function _classCallCheck(instance, Constructor) { | |
77 if (!(instance instanceof Constructor)) { | |
78 throw new TypeError('Cannot call a class as a function'); | |
79 } | |
80 } | |
81 | |
82 function Babel() { | |
83 'use strict'; | |
84 var Point = function Point(x, y) { | |
85 _classCallCheck(this, Point); | |
86 | |
87 this.x = x; | |
88 this.y = y; | |
89 }; | |
90 | |
91 var MyPoint = function(_Point) { | |
92 _inherits(MyPoint, _Point); | |
93 | |
94 function MyPoint() { | |
95 _classCallCheck(this, MyPoint); | |
96 | |
97 return _possibleConstructorReturn( | |
98 this, (MyPoint.__proto__ || Object.getPrototypeOf(MyPoint)) | |
99 .apply(this, arguments)); | |
100 } | |
101 | |
102 return MyPoint; | |
103 }(Point); | |
104 | |
105 function makePoint(x, y) { | |
106 return new MyPoint(x, y); | |
107 } | |
108 | |
109 return makePoint(1, 2); | |
110 } | |
111 | |
112 // ---------------------------------------------------------------------------- | |
113 // Benchmark: ES6 | |
114 // ---------------------------------------------------------------------------- | |
115 | |
116 function ES6() { | |
117 'use strict'; | |
118 | |
119 class Point { | |
120 constructor(x, y) { | |
121 this.x = x; | |
122 this.y = y; | |
123 } | |
124 } | |
125 | |
126 class MyPoint extends Point {} | |
127 | |
128 function makePoint(x, y) { | |
129 return new MyPoint(x, y); | |
130 } | |
131 | |
132 return makePoint(1, 2); | |
133 } | |
OLD | NEW |