Created
February 17, 2016 18:01
-
-
Save mhowlett/91369339fa1a80726a7e to your computer and use it in GitHub Desktop.
test for array vs object allocation speed / heap sizes
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
<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