Created
September 16, 2018 00:56
-
-
Save developit/fe94f7f2191470fa83d5a090ac1767bd to your computer and use it in GitHub Desktop.
deoptigate -- node --allow-natives-syntax *.js
This file contains hidden or 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
const { performance } = require('perf_hooks'); | |
const h1 = (tag, props, children) => ({ tag, props, children }) | |
const h2 = (tag, props, children) => ({ tag, props, children }) | |
function serializeProps(props) { | |
let out = ''; | |
for (let i in props) out += ` ${i}="${props[i]}"`; | |
return out; | |
} | |
let start, end; | |
const ITER = 500000; | |
start = performance.now(); | |
const vnodes1 = []; | |
for (let i=ITER; i--; ) { | |
const vnode = h1('h'+i, {i}, ['index: ', i]); | |
const html = `<${vnode.tag}${serializeProps(vnode.props)}>${vnode.children.join('')}</${vnode.tag}>`; | |
vnode._rendered = html; | |
vnodes1.push(vnode); | |
} | |
console.log(vnodes1.map(v => v._rendered).join('').length); | |
end = performance.now(); | |
console.log('string: ', (end - start)|0); | |
start = performance.now(); | |
const vnodes2 = []; | |
const RENDERED = 42; | |
for (let i=ITER; i--; ) { | |
const vnode = h2('h'+i, {i}, ['index: ', i]); | |
const html = `<${vnode.tag}${serializeProps(vnode.props)}>${vnode.children.join('')}</${vnode.tag}>`; | |
vnode[RENDERED] = html; | |
vnodes2.push(vnode); | |
} | |
console.log(vnodes2.map(v => v[RENDERED]).join('').length); | |
end = performance.now(); | |
console.log('array: ', (end - start)|0); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment