Skip to content

Instantly share code, notes, and snippets.

@mhowlett
Created February 17, 2016 18:01
Show Gist options
  • Save mhowlett/91369339fa1a80726a7e to your computer and use it in GitHub Desktop.
Save mhowlett/91369339fa1a80726a7e to your computer and use it in GitHub Desktop.
test for array vs object allocation speed / heap sizes
<html>
<script type="text/javascript">
var testObj = function() {
var a = [];
var i = 0;
for (; i<10000000; ++i) {
a.push({
time: Math.random(),
value: Math.random()
});
}
console.log(a.length);
}
var testArray = function() {
var a = [];
var b = [];
var i = 0;
for (; i<10000000; ++i) {
a.push(Math.random());
b.push(Math.random());
}
console.log(a.length, b.length);
}
</script>
<body>
<button onclick="testObj();">test object</button>
<button onclick="testArray();">test array</button>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment