| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 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 | |
| 9 new BenchmarkSuite('Spread-ES5', [1000], [ | |
| 10 new Benchmark('ES5', false, false, 0, ES5), | |
| 11 ]); | |
| 12 | |
| 13 new BenchmarkSuite('Spread-Traceur', [1000], [ | |
| 14 new Benchmark('Traceur', false, false, 0, Traceur), | |
| 15 ]); | |
| 16 | |
| 17 new BenchmarkSuite('Spread-ES6', [1000], [ | |
| 18 new Benchmark('ES6', false, false, 0, ES6), | |
| 19 ]); | |
| 20 | |
| 21 // ---------------------------------------------------------------------------- | |
| 22 // Benchmark: ES5 | |
| 23 // ---------------------------------------------------------------------------- | |
| 24 | |
| 25 function ES5() { | |
| 26 "use strict"; | |
| 27 return Math.max.apply(Math, [1,2,3]); | |
| 28 } | |
| 29 | |
| 30 // ---------------------------------------------------------------------------- | |
| 31 // Benchmark: Traceur | |
| 32 // ---------------------------------------------------------------------------- | |
| 33 | |
| 34 function checkObjectCoercible(v) { | |
| 35 "use strict"; | |
| 36 if (v === null || v === undefined) { | |
| 37 throw new $TypeError('Value cannot be converted to an Object'); | |
| 38 } | |
| 39 return v; | |
| 40 } | |
| 41 | |
| 42 function spread() { | |
| 43 "use strict"; | |
| 44 var rv = [], | |
| 45 j = 0, | |
| 46 iterResult; | |
| 47 for (var i = 0; i < arguments.length; i++) { | |
| 48 var valueToSpread = checkObjectCoercible(arguments[i]); | |
| 49 if (typeof valueToSpread[Symbol.iterator] !== 'function') { | |
| 50 throw new TypeError('Cannot spread non-iterable object.'); | |
| 51 } | |
| 52 var iter = valueToSpread[Symbol.iterator](); | |
| 53 while (!(iterResult = iter.next()).done) { | |
| 54 rv[j++] = iterResult.value; | |
| 55 } | |
| 56 } | |
| 57 return rv; | |
| 58 } | |
| 59 | |
| 60 function Traceur() { | |
| 61 "use strict"; | |
| 62 var $__0; | |
| 63 return ($__0 = Math).max.apply($__0, spread([1, 2, 3])); | |
| 64 } | |
| 65 | |
| 66 // ---------------------------------------------------------------------------- | |
| 67 // Benchmark: ES6 | |
| 68 // ---------------------------------------------------------------------------- | |
| 69 | |
| 70 function ES6() { | |
| 71 "use strict"; | |
| 72 return Math.max(...[1,2,3]); | |
| 73 } | |
| OLD | NEW |