Skip to content

Instantly share code, notes, and snippets.

@StoneCypher
Created June 10, 2017 22:18
Show Gist options
  • Save StoneCypher/327e1a0e8b8820b57fc6020a4e290b5a to your computer and use it in GitHub Desktop.
Save StoneCypher/327e1a0e8b8820b57fc6020a4e290b5a to your computer and use it in GitHub Desktop.
<!doctype html>
<html>
<head>
<script type="text/javascript">
function now() { return new Date().getTime(); }
function for_n(n) {
const tr = document.createElement('tr'),
with_p = new Array(n),
without = new Array();
const first = now();
for (var i=0; i<n; ++i) { with_p.push(n); }
const second = now();
for (var i=0; i<n; ++i) { without.push(n); }
const third = now();
const count = document.createElement('td');
count.innerHTML = n;
const wo_t = second - first,
w_t = third - second;
const wo_td = document.createElement('td');
wo_td.innerHTML = wo_t;
const w_td = document.createElement('td');
w_td.innerHTML = w_t;
tr.appendChild(count);
tr.appendChild(w_td);
tr.appendChild(wo_td);
document.getElementById('tgt').appendChild(tr);
// [count, w_td. wo_td].map(td => tr.appendChild(td) );
}
window.onload = function() {
[1e2, 1e3, 1e4, 1e5, 1e6, 1e7].map(n => for_n(n));
}
</script>
</head>
<body>
<table>
<thead><th>Count</th><th>With<br/>prealloc</th><th>Without<br/>prealloc</th></tr>
<tbody id="tgt"></tbody>
</table>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment