Last active
November 17, 2016 06:09
-
-
Save bmeurer/4519494a5f2a96228c505bd85e19cf8d to your computer and use it in GitHub Desktop.
Destructuring performace (V8 ToT 2016/11/16)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///////////////////////////////////////////////////////////////////////////// | |
// Test framework: | |
// Warmup | |
for (var i = 0; i < 1000; ++i) test(data); | |
function time(test, a) { | |
let startTime = Date.now(); | |
// Using F.p.apply here to prevent inlining, so we can really | |
// just measure the performance of test stand-alone. | |
for (let i = 0; i < 5000000; ++i) test.apply(undefined, [a]); | |
let endTime = Date.now(); | |
print("Time: " + (endTime - startTime) + "ms."); | |
} | |
time(test, data); | |
///////////////////////////////////////////////////////////////////////////// | |
// Test data (Source: https://fhinkel.github.io/six-speed) | |
var data = { | |
a: 'foo', | |
b: {c: 'd'}, | |
arr: [1, 2, 3] | |
}; | |
///////////////////////////////////////////////////////////////////////////// | |
// Naive ES5 version (Source: https://fhinkel.github.io/six-speed) | |
function test(data) { | |
var a = data.a, | |
b = data.b.c, | |
c = data.arr[1]; | |
return c; | |
} | |
///////////////////////////////////////////////////////////////////////////// | |
// ES6 destructuring version (Source: https://fhinkel.github.io/six-speed) | |
function test(data) { | |
var {a, b:{c:b}, arr:[, c]} = data; | |
return c; | |
} | |
///////////////////////////////////////////////////////////////////////////// | |
// Results (with experimental TurboFan escape analysis): | |
// | |
// $ d8 --turbo-escape destructuring.es5 | |
// Time: 275ms. | |
// | |
// $ d8 --turbo-escape destructuring.es6 | |
// Time: 344ms. | |
// | |
// State: 20% missing for ES6 version to reach parity. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment